diff --git a/.github/workflows/release_zips.yml b/.github/workflows/release_zips.yml index a88dd90128e8..ccce907041e8 100644 --- a/.github/workflows/release_zips.yml +++ b/.github/workflows/release_zips.yml @@ -10,8 +10,8 @@ jobs: name: Create release zip file runs-on: ubuntu-20.04 steps: - - name: Create a recursive clone source zip - uses: espressif/github-actions/release_zips@master + - name: Create a recursive clone source and stripped zip + uses: Jason2866/github-actions/release_zips@release_idf env: RELEASE_PROJECT_NAME: ESP-IDF GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitmodules b/.gitmodules index ee3fd858e0cc..3caaeb8ecb9a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,15 +37,6 @@ sbom-description = A small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors sbom-hash = 24c60e243580c7868f4334a1ba3123481fe1aa48 -[submodule "components/spiffs/spiffs"] - path = components/spiffs/spiffs - url = ../../pellepl/spiffs.git - sbom-version = 0.2-255-g0dbb3f71c5f6 - sbom-supplier = Person: Peter Andersson - sbom-url = https://github.com/pellepl/spiffs - sbom-description = Wear-leveled SPI flash file system for embedded devices - sbom-hash = 0dbb3f71c5f6fae3747a9d935372773762baf852 - [submodule "components/json/cJSON"] path = components/json/cJSON url = ../../DaveGamble/cJSON.git diff --git a/components/esp_driver_dac/dac_continuous.c b/components/esp_driver_dac/dac_continuous.c index b3f8f9c25e01..a34b1a2c141b 100644 --- a/components/esp_driver_dac/dac_continuous.c +++ b/components/esp_driver_dac/dac_continuous.c @@ -555,16 +555,17 @@ static esp_err_t s_dac_wait_to_load_dma_data(dac_continuous_handle_t handle, uin DAC_STAILQ_REMOVE(&handle->head, desc, lldesc_s, qe); } - static bool split_flag = false; + // TASMOTA: remove split because it does some harm and I'm not sure why it was there in the first place. No such code in 4.x + // static bool split_flag = false; uint8_t *dma_buf = (uint8_t *)desc->buf; - if (buf_size * DAC_16BIT_ALIGN_COEFF < 2 * handle->cfg.buf_size) { - if (!split_flag) { - buf_size >>= 1; - split_flag = true; - } else { - split_flag = false; - } - } + // if (buf_size * DAC_16BIT_ALIGN_COEFF < 2 * handle->cfg.buf_size) { + // if (!split_flag) { + // buf_size >>= 1; + // split_flag = true; + // } else { + // split_flag = false; + // } + // } size_t load_bytes = s_dac_load_data_into_buf(handle, dma_buf, handle->cfg.buf_size, buf, buf_size); lldesc_config(desc, LLDESC_HW_OWNED, 1, 0, load_bytes); desc->size = load_bytes; diff --git a/components/esp_eth/CMakeLists.txt b/components/esp_eth/CMakeLists.txt index 132f01a30110..b432f557810f 100644 --- a/components/esp_eth/CMakeLists.txt +++ b/components/esp_eth/CMakeLists.txt @@ -34,7 +34,8 @@ if(CONFIG_ETH_ENABLED) "src/phy/esp_eth_phy_ip101.c" "src/phy/esp_eth_phy_ksz80xx.c" "src/phy/esp_eth_phy_lan87xx.c" - "src/phy/esp_eth_phy_rtl8201.c") + "src/phy/esp_eth_phy_rtl8201.c" + "src/phy/esp_eth_phy_jl1101.c") endif() if(CONFIG_ETH_SPI_ETHERNET_DM9051) diff --git a/components/esp_eth/include/esp_eth_phy.h b/components/esp_eth/include/esp_eth_phy.h index 82c16aef41d0..5613b8749744 100644 --- a/components/esp_eth/include/esp_eth_phy.h +++ b/components/esp_eth/include/esp_eth_phy.h @@ -352,6 +352,17 @@ esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config); */ esp_eth_phy_t *esp_eth_phy_new_ksz80xx(const eth_phy_config_t *config); +/** +* @brief Create a PHY instance of JL1101 +* +* @param[in] config: configuration of PHY +* +* @return +* - instance: create PHY instance successfully +* - NULL: create PHY instance failed because some error occurred +*/ +esp_eth_phy_t *esp_eth_phy_new_jl1101(const eth_phy_config_t *config); + #if CONFIG_ETH_SPI_ETHERNET_DM9051 /** * @brief Create a PHY instance of DM9051 diff --git a/components/esp_eth/src/phy/esp_eth_phy_jl1101.c b/components/esp_eth/src/phy/esp_eth_phy_jl1101.c new file mode 100644 index 000000000000..512e5fe024f5 --- /dev/null +++ b/components/esp_eth/src/phy/esp_eth_phy_jl1101.c @@ -0,0 +1,186 @@ +/* + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "esp_log.h" +#include "esp_check.h" +#include "esp_eth_phy_802_3.h" + +static const char *TAG = "jl1101"; + +/***************Vendor Specific Register***************/ + +/** + * @brief PSMR(Power Saving Mode Register) + * + */ +typedef union { + struct { + uint16_t reserved : 15; /* Reserved */ + uint16_t en_pwr_save : 1; /* Enable power saving mode */ + }; + uint16_t val; +} psmr_reg_t; + +/** + * @brief PSR(Page Select Register) + * + */ +typedef union { + struct { + uint16_t page_select : 8; /* Select register page, default is 0 */ + uint16_t reserved : 8; /* Reserved */ + }; + uint16_t val; +} psr_reg_t; +#define ETH_PHY_PSR_REG_ADDR (0x1F) + +typedef struct { + phy_802_3_t phy_802_3; +} phy_jl1101_t; + +static esp_err_t jl1101_page_select(phy_jl1101_t *jl1101, uint32_t page) +{ + esp_err_t ret = ESP_OK; + esp_eth_mediator_t *eth = jl1101->phy_802_3.eth; + psr_reg_t psr = { + .page_select = page + }; + ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, jl1101->phy_802_3.addr, ETH_PHY_PSR_REG_ADDR, psr.val), err, TAG, "write PSR failed"); + return ESP_OK; +err: + return ret; +} + +static esp_err_t jl1101_update_link_duplex_speed(phy_jl1101_t *jl1101) +{ + esp_err_t ret = ESP_OK; + esp_eth_mediator_t *eth = jl1101->phy_802_3.eth; + uint32_t addr = jl1101->phy_802_3.addr; + eth_speed_t speed = ETH_SPEED_10M; + eth_duplex_t duplex = ETH_DUPLEX_HALF; + bmcr_reg_t bmcr; + bmsr_reg_t bmsr; + uint32_t peer_pause_ability = false; + anlpar_reg_t anlpar; + ESP_GOTO_ON_ERROR(jl1101_page_select(jl1101, 0), err, TAG, "select page 0 failed"); + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)), err, TAG, "read BMSR failed"); + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, addr, ETH_PHY_ANLPAR_REG_ADDR, &(anlpar.val)), err, TAG, "read ANLPAR failed"); + eth_link_t link = bmsr.link_status ? ETH_LINK_UP : ETH_LINK_DOWN; + /* check if link status changed */ + if (jl1101->phy_802_3.link_status != link) { + /* when link up, read negotiation result */ + if (link == ETH_LINK_UP) { + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed"); + if (bmcr.speed_select) { + speed = ETH_SPEED_100M; + } else { + speed = ETH_SPEED_10M; + } + if (bmcr.duplex_mode) { + duplex = ETH_DUPLEX_FULL; + } else { + duplex = ETH_DUPLEX_HALF; + } + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_SPEED, (void *)speed), err, TAG, "change speed failed"); + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_DUPLEX, (void *)duplex), err, TAG, "change duplex failed"); + /* if we're in duplex mode, and peer has the flow control ability */ + if (duplex == ETH_DUPLEX_FULL && anlpar.symmetric_pause) { + peer_pause_ability = 1; + } else { + peer_pause_ability = 0; + } + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_PAUSE, (void *)peer_pause_ability), err, TAG, "change pause ability failed"); + } + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LINK, (void *)link), err, TAG, "change link failed"); + jl1101->phy_802_3.link_status = link; + } + return ESP_OK; +err: + return ret; +} + +static esp_err_t jl1101_get_link(esp_eth_phy_t *phy) +{ + esp_err_t ret = ESP_OK; + phy_jl1101_t *jl1101 = __containerof(esp_eth_phy_into_phy_802_3(phy), phy_jl1101_t, phy_802_3); + /* Updata information about link, speed, duplex */ + ESP_GOTO_ON_ERROR(jl1101_update_link_duplex_speed(jl1101), err, TAG, "update link duplex speed failed"); + return ESP_OK; +err: + return ret; +} + +static esp_err_t jl1101_autonego_ctrl(esp_eth_phy_t *phy, eth_phy_autoneg_cmd_t cmd, bool *autonego_en_stat) +{ + esp_err_t ret = ESP_OK; + phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy); + esp_eth_mediator_t *eth = phy_802_3->eth; + if (cmd == ESP_ETH_PHY_AUTONEGO_EN) { + bmcr_reg_t bmcr; + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, phy_802_3->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed"); + ESP_GOTO_ON_FALSE(bmcr.en_loopback == 0, ESP_ERR_INVALID_STATE, err, TAG, "Autonegotiation can't be enabled while in loopback operation"); + } + return esp_eth_phy_802_3_autonego_ctrl(phy_802_3, cmd, autonego_en_stat); +err: + return ret; +} + +static esp_err_t jl1101_loopback(esp_eth_phy_t *phy, bool enable) +{ + esp_err_t ret = ESP_OK; + phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy); + bool auto_nego_en; + ESP_GOTO_ON_ERROR(jl1101_autonego_ctrl(phy, ESP_ETH_PHY_AUTONEGO_G_STAT, &auto_nego_en), err, TAG, "get status of autonegotiation failed"); + ESP_GOTO_ON_FALSE(!(auto_nego_en && enable), ESP_ERR_INVALID_STATE, err, TAG, "Unable to set loopback while autonegotiation is enabled. Disable it to use loopback"); + return esp_eth_phy_802_3_loopback(phy_802_3, enable); +err: + return ret; +} + +static esp_err_t jl1101_init(esp_eth_phy_t *phy) +{ + esp_err_t ret = ESP_OK; + phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy); + + /* Basic PHY init */ + ESP_GOTO_ON_ERROR(esp_eth_phy_802_3_basic_phy_init(phy_802_3), err, TAG, "failed to init PHY"); + + /* Check PHY ID */ + uint32_t oui; + uint8_t model; + ESP_GOTO_ON_ERROR(esp_eth_phy_802_3_read_oui(phy_802_3, &oui), err, TAG, "read OUI failed"); + ESP_GOTO_ON_ERROR(esp_eth_phy_802_3_read_manufac_info(phy_802_3, &model, NULL), err, TAG, "read manufacturer's info failed"); + ESP_GOTO_ON_FALSE(oui == 0x24DF10 && model == 0x2, ESP_FAIL, err, TAG, "wrong chip ID"); + + return ESP_OK; +err: + return ret; +} + +esp_eth_phy_t *esp_eth_phy_new_jl1101(const eth_phy_config_t *config) +{ + esp_eth_phy_t *ret = NULL; + phy_jl1101_t *jl1101 = calloc(1, sizeof(phy_jl1101_t)); + ESP_GOTO_ON_FALSE(jl1101, NULL, err, TAG, "calloc jl1101 failed"); + ESP_GOTO_ON_FALSE(esp_eth_phy_802_3_obj_config_init(&jl1101->phy_802_3, config) == ESP_OK, + NULL, err, TAG, "configuration initialization of PHY 802.3 failed"); + + // redefine functions which need to be customized for sake of jl1101 + jl1101->phy_802_3.parent.init = jl1101_init; + jl1101->phy_802_3.parent.get_link = jl1101_get_link; + jl1101->phy_802_3.parent.autonego_ctrl = jl1101_autonego_ctrl; + jl1101->phy_802_3.parent.loopback = jl1101_loopback; + + return &jl1101->phy_802_3.parent; +err: + if (jl1101 != NULL) { + free(jl1101); + } + return ret; +} diff --git a/components/esp_hw_support/mac_addr.c b/components/esp_hw_support/mac_addr.c index 6059a92aafc4..ac72aea9dff0 100644 --- a/components/esp_hw_support/mac_addr.c +++ b/components/esp_hw_support/mac_addr.c @@ -287,6 +287,8 @@ static esp_err_t get_efuse_factory_mac(uint8_t *mac) uint32_t mac_low = ((uint32_t)mac[2] << 24) | ((uint32_t)mac[3] << 16) | ((uint32_t)mac[4] << 8) | mac[5]; if (((mac_high & 0xFFFF) == 0x18fe) && (mac_low >= 0x346a85c7) && (mac_low <= 0x346a85f8)) { return ESP_OK; + } else if (esp_efuse_get_pkg_ver() == 3) { + return ESP_OK; // override for Xiaomi SOC's and maybe others too } else { ESP_LOGE(TAG, "Base MAC address from BLK0 of EFUSE CRC error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc); #ifdef CONFIG_ESP_MAC_IGNORE_MAC_CRC_ERROR diff --git a/components/esp_psram/esp32/esp_psram_impl_quad.c b/components/esp_psram/esp32/esp_psram_impl_quad.c index 20a90e902763..a216f0ce5df8 100644 --- a/components/esp_psram/esp32/esp_psram_impl_quad.c +++ b/components/esp_psram/esp32/esp_psram_impl_quad.c @@ -866,7 +866,7 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(void) //psram init psram_io.psram_cs_io = D2WD_PSRAM_CS_IO; } else if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 && ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 300)) { ESP_EARLY_LOGE(TAG, "This chip is ESP32-PICO-V3. It does not support PSRAM (disable it in Kconfig)"); - abort(); + return ESP_FAIL; } else if ((pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) || (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH)) { ESP_EARLY_LOGI(TAG, "This chip is %s", (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) ? "ESP32-PICO" : "ESP32-U4WDH"); @@ -903,7 +903,7 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(void) //psram init psram_io.psram_cs_io = D0WDR2_V3_PSRAM_CS_IO; } else { ESP_EARLY_LOGE(TAG, "Not a valid or known package id: %" PRIu32, pkg_ver); - abort(); + return ESP_FAIL; } s_psram_cs_io = psram_io.psram_cs_io; diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 67f268c8fd73..164902a9cd5b 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -299,7 +299,7 @@ menu "Wi-Fi" config ESP_WIFI_ENABLE_WPA3_SAE bool "Enable WPA3-Personal" default y - select ESP_WIFI_MBEDTLS_CRYPTO + depends on ESP_WIFI_MBEDTLS_CRYPTO help Select this option to allow the device to establish a WPA3-Personal connection with eligible AP's. PMF (Protected Management Frames) is a prerequisite feature for a WPA3 connection, it needs to be @@ -491,16 +491,9 @@ menu "Wi-Fi" select MBEDTLS_ECP_C select MBEDTLS_ECDH_C select MBEDTLS_ECDSA_C - select MBEDTLS_CMAC_C - select MBEDTLS_ECP_DP_SECP256R1_ENABLED + select MBEDTLS_TLS_ENABLED help - Select this option to enable the use of MbedTLS crypto APIs. - The internal crypto support within the supplicant is limited - and may not suffice for all new security features, including WPA3. - - It is recommended to always keep this option enabled. Additionally, - note that MbedTLS can leverage hardware acceleration if available, - resulting in significantly faster cryptographic operations. + Select this option to use MbedTLS crypto APIs which utilize hardware acceleration. if ESP_WIFI_MBEDTLS_CRYPTO config ESP_WIFI_MBEDTLS_TLS_CLIENT @@ -541,7 +534,6 @@ menu "Wi-Fi" config ESP_WIFI_SUITE_B_192 bool "Enable NSA suite B support with 192 bit key" default n - depends on SOC_WIFI_GCMP_SUPPORT select ESP_WIFI_GCMP_SUPPORT select ESP_WIFI_GMAC_SUPPORT help diff --git a/components/hal/esp32p4/include/hal/i2c_ll.h b/components/hal/esp32p4/include/hal/i2c_ll.h index e4fdb1622b85..a9f4c8e0dee5 100644 --- a/components/hal/esp32p4/include/hal/i2c_ll.h +++ b/components/hal/esp32p4/include/hal/i2c_ll.h @@ -150,6 +150,7 @@ static inline void i2c_ll_enable_bus_clock(int i2c_port, bool enable) /// use a macro to wrap the function, force the caller to use it in a critical section /// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance +int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_ATOMIC_ENV #define i2c_ll_enable_bus_clock(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; i2c_ll_enable_bus_clock(__VA_ARGS__);} while(0) /** @@ -170,6 +171,7 @@ static inline void i2c_ll_reset_register(int i2c_port) /// use a macro to wrap the function, force the caller to use it in a critical section /// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance +int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_ATOMIC_ENV #define i2c_ll_reset_register(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; i2c_ll_reset_register(__VA_ARGS__);} while(0) /** @@ -796,6 +798,7 @@ static inline void i2c_ll_set_source_clk(i2c_dev_t *hw, i2c_clock_source_t src_c /// use a macro to wrap the function, force the caller to use it in a critical section /// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance +int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_ATOMIC_ENV #define i2c_ll_set_source_clk(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; i2c_ll_set_source_clk(__VA_ARGS__);} while(0) /** diff --git a/components/hal/esp32p4/include/hal/uart_ll.h b/components/hal/esp32p4/include/hal/uart_ll.h index 70560c235d7b..c6cb69efd985 100644 --- a/components/hal/esp32p4/include/hal/uart_ll.h +++ b/components/hal/esp32p4/include/hal/uart_ll.h @@ -478,6 +478,7 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, soc_module_clk_t *source */ FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { +int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_ATOMIC_ENV #define DIV_UP(a, b) (((a) + (b) - 1) / (b)) const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud); @@ -507,7 +508,7 @@ FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint3 } #if !BOOTLOADER_BUILD //HP_SYS_CLKRST.peri_clk_ctrlxxx are shared registers, so this function must be used in an atomic way -#define uart_ll_set_baudrate(...) (void)__DECLARE_RCC_ATOMIC_ENV; uart_ll_set_baudrate(__VA_ARGS__) +#define uart_ll_set_baudrate(...) #endif /** diff --git a/components/hal/include/hal/i2c_hal.h b/components/hal/include/hal/i2c_hal.h index b7f7518e1f4b..da3155c728f6 100644 --- a/components/hal/include/hal/i2c_hal.h +++ b/components/hal/include/hal/i2c_hal.h @@ -98,6 +98,7 @@ void _i2c_hal_set_bus_timing(i2c_hal_context_t *hal, int scl_freq, i2c_clock_sou #if SOC_PERIPH_CLK_CTRL_SHARED /// use a macro to wrap the function, force the caller to use it in a critical section /// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance +int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_ATOMIC_ENV #define i2c_hal_set_bus_timing(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; _i2c_hal_set_bus_timing(__VA_ARGS__);} while(0) #else #define i2c_hal_set_bus_timing(...) _i2c_hal_set_bus_timing(__VA_ARGS__) diff --git a/components/soc/esp32c2/include/soc/soc.h b/components/soc/esp32c2/include/soc/soc.h index b271cc2ca29d..6472ec14fb2e 100644 --- a/components/soc/esp32c2/include/soc/soc.h +++ b/components/soc/esp32c2/include/soc/soc.h @@ -30,7 +30,7 @@ #define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) -#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (0)) // only one GPSPI +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // only one GPSPI #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Registers Operation {{ diff --git a/components/soc/esp32c3/include/soc/soc.h b/components/soc/esp32c3/include/soc/soc.h index b4969ec81190..b4b3074ca781 100644 --- a/components/soc/esp32c3/include/soc/soc.h +++ b/components/soc/esp32c3/include/soc/soc.h @@ -23,7 +23,7 @@ #define REG_I2S_BASE(i) (DR_REG_I2S_BASE) // only one I2S on C3 #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) -#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (0)) // only one GPSPI +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // only one GPSPI #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Registers Operation {{ diff --git a/components/soc/esp32c6/include/soc/soc.h b/components/soc/esp32c6/include/soc/soc.h index 7986a5c2f129..e6ffdcd0b8f1 100644 --- a/components/soc/esp32c6/include/soc/soc.h +++ b/components/soc/esp32c6/include/soc/soc.h @@ -23,7 +23,7 @@ #define REG_I2S_BASE(i) (DR_REG_I2S_BASE) // only one I2S on C6 #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i) * 0x1000) // TIMERG0 and TIMERG1 #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE + (i) * 0x1000) // SPIMEM0 and SPIMEM1 -#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (0)) // only one GPSPI on C6 +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // only one GPSPI on C6 #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE) // only one I2C on C6 #define REG_MCPWM_BASE(i) (DR_REG_MCPWM_BASE) // only one MCPWM on C6 #define REG_TWAI_BASE(i) (DR_REG_TWAI0_BASE + (i) * 0x2000) // TWAI0 and TWAI1 diff --git a/components/soc/esp32h2/include/soc/soc.h b/components/soc/esp32h2/include/soc/soc.h index 1191c37e612b..3da3bf4090e4 100644 --- a/components/soc/esp32h2/include/soc/soc.h +++ b/components/soc/esp32h2/include/soc/soc.h @@ -23,7 +23,7 @@ #define REG_I2S_BASE(i) (DR_REG_I2S_BASE) // only one I2S on H2 #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE + (i) * 0x1000) -#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (0)) // only one GPSPI +#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (i - 2) * 0x1000) // only one GPSPI #define REG_I2C_BASE(i) (DR_REG_I2C_EXT0_BASE + (i) * 0x1000) //Registers Operation {{ diff --git a/components/soc/esp32s2/include/soc/soc.h b/components/soc/esp32s2/include/soc/soc.h index 6bca2b7bea3b..b19a0b1f8f48 100644 --- a/components/soc/esp32s2/include/soc/soc.h +++ b/components/soc/esp32s2/include/soc/soc.h @@ -25,7 +25,7 @@ #define REG_I2S_BASE( i ) (DR_REG_I2S_BASE) #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) -#define REG_SPI_BASE(i) (((i)>=2) ? (DR_REG_SPI2_BASE + (i-2) * 0x1000) : (0)) // GPSPI2 and GPSPI3 +#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (((i)>3) ? (((i-2)* 0x1000) + 0x10000) : ((i - 2)* 0x1000 ))) // GPSPI2 and GPSPI3 #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Convenient way to replace the register ops when ulp riscv projects diff --git a/components/soc/esp32s3/include/soc/soc.h b/components/soc/esp32s3/include/soc/soc.h index 2600af7e59f4..5c9c67082df3 100644 --- a/components/soc/esp32s3/include/soc/soc.h +++ b/components/soc/esp32s3/include/soc/soc.h @@ -34,7 +34,7 @@ #define REG_I2S_BASE( i ) (DR_REG_I2S_BASE + (i) * 0x1E000) #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) -#define REG_SPI_BASE(i) (((i)>=2) ? (DR_REG_SPI2_BASE + (i-2) * 0x1000) : (0)) // GPSPI2 and GPSPI3 +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // GPSPI2 and GPSPI3 #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Convenient way to replace the register ops when ulp riscv projects diff --git a/components/spiffs/CMakeLists.txt b/components/spiffs/CMakeLists.txt deleted file mode 100644 index 142ad9ec29ef..000000000000 --- a/components/spiffs/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -idf_build_get_property(target IDF_TARGET) - -set(original_srcs "spiffs/src/spiffs_cache.c" - "spiffs/src/spiffs_check.c" - "spiffs/src/spiffs_gc.c" - "spiffs/src/spiffs_hydrogen.c" - "spiffs/src/spiffs_nucleus.c") - -list(APPEND srcs "spiffs_api.c" ${original_srcs}) - -if(NOT ${target} STREQUAL "linux") - list(APPEND pr bootloader_support esptool_py vfs) - list(APPEND srcs "esp_spiffs.c") -endif() - -idf_component_register(SRCS ${srcs} - INCLUDE_DIRS "include" - PRIV_INCLUDE_DIRS "." "spiffs/src" - REQUIRES esp_partition - PRIV_REQUIRES ${pr} spi_flash) - -if(CMAKE_C_COMPILER_ID MATCHES "GNU") - set_source_files_properties(spiffs/src/spiffs_nucleus.c PROPERTIES COMPILE_FLAGS -Wno-stringop-truncation) -endif() - -# Upstream SPIFFS code uses format specifiers in debug logging macros inconsistently -set_source_files_properties(${original_srcs} PROPERTIES COMPILE_FLAGS -Wno-format) diff --git a/components/spiffs/Kconfig b/components/spiffs/Kconfig deleted file mode 100644 index 2ae23d4d9592..000000000000 --- a/components/spiffs/Kconfig +++ /dev/null @@ -1,181 +0,0 @@ -menu "SPIFFS Configuration" - - config SPIFFS_MAX_PARTITIONS - int "Maximum Number of Partitions" - default 3 - range 1 10 - help - Define maximum number of partitions that can be mounted. - - menu "SPIFFS Cache Configuration" - config SPIFFS_CACHE - bool "Enable SPIFFS Cache" - default "y" - help - Enables/disable memory read caching of nucleus file system - operations. - - config SPIFFS_CACHE_WR - bool "Enable SPIFFS Write Caching" - default "y" - depends on SPIFFS_CACHE - help - Enables memory write caching for file descriptors in hydrogen. - - config SPIFFS_CACHE_STATS - bool "Enable SPIFFS Cache Statistics" - default "n" - depends on SPIFFS_CACHE - help - Enable/disable statistics on caching. Debug/test purpose only. - - endmenu - - config SPIFFS_PAGE_CHECK - bool "Enable SPIFFS Page Check" - default "y" - help - Always check header of each accessed page to ensure consistent state. - If enabled it will increase number of reads from flash, especially - if cache is disabled. - - config SPIFFS_GC_MAX_RUNS - int "Set Maximum GC Runs" - default 10 - range 1 10000 - help - Define maximum number of GC runs to perform to reach desired free pages. - - config SPIFFS_GC_STATS - bool "Enable SPIFFS GC Statistics" - default "n" - help - Enable/disable statistics on gc. Debug/test purpose only. - - config SPIFFS_PAGE_SIZE - int "SPIFFS logical page size" - default 256 - range 256 1024 - help - Logical page size of SPIFFS partition, in bytes. Must be multiple - of flash page size (which is usually 256 bytes). - Larger page sizes reduce overhead when storing large files, and - improve filesystem performance when reading large files. - Smaller page sizes reduce overhead when storing small (< page size) - files. - - config SPIFFS_OBJ_NAME_LEN - int "Set SPIFFS Maximum Name Length" - default 32 - range 1 256 - help - Object name maximum length. Note that this length include the - zero-termination character, meaning maximum string of characters - can at most be SPIFFS_OBJ_NAME_LEN - 1. - - SPIFFS_OBJ_NAME_LEN + SPIFFS_META_LENGTH should not exceed - SPIFFS_PAGE_SIZE - 64. - - config SPIFFS_FOLLOW_SYMLINKS - bool "Enable symbolic links for image creation" - default "n" - help - If this option is enabled, symbolic links are taken into account - during partition image creation. - - config SPIFFS_USE_MAGIC - bool "Enable SPIFFS Filesystem Magic" - default "y" - help - Enable this to have an identifiable spiffs filesystem. - This will look for a magic in all sectors to determine if this - is a valid spiffs system or not at mount time. - - config SPIFFS_USE_MAGIC_LENGTH - bool "Enable SPIFFS Filesystem Length Magic" - default "y" - depends on SPIFFS_USE_MAGIC - help - If this option is enabled, the magic will also be dependent - on the length of the filesystem. For example, a filesystem - configured and formatted for 4 megabytes will not be accepted - for mounting with a configuration defining the filesystem as 2 megabytes. - - config SPIFFS_META_LENGTH - int "Size of per-file metadata field" - default 4 - help - This option sets the number of extra bytes stored in the file header. - These bytes can be used in an application-specific manner. - Set this to at least 4 bytes to enable support for saving file - modification time. - - SPIFFS_OBJ_NAME_LEN + SPIFFS_META_LENGTH should not exceed - SPIFFS_PAGE_SIZE - 64. - - config SPIFFS_USE_MTIME - bool "Save file modification time" - default "y" - depends on SPIFFS_META_LENGTH >= 4 - help - If enabled, then the first 4 bytes of per-file metadata will be used - to store file modification time (mtime), accessible through - stat/fstat functions. - Modification time is updated when the file is opened. - - config SPIFFS_MTIME_WIDE_64_BITS - bool "The time field occupies 64 bits in the image instead of 32 bits" - default n - depends on SPIFFS_META_LENGTH >= 8 - help - If this option is not set, the time field is 32 bits (up to 2106 year), - otherwise it is 64 bits and make sure it matches SPIFFS_META_LENGTH. - If the chip already has the spiffs image with the time field = 32 bits - then this option cannot be applied in this case. - Erase it first before using this option. - To resolve the Y2K38 problem for the spiffs, use a toolchain with - 64-bit time_t support. - - menu "Debug Configuration" - - config SPIFFS_DBG - bool "Enable general SPIFFS debug" - default "n" - help - Enabling this option will print general debug messages to the console. - - config SPIFFS_API_DBG - bool "Enable SPIFFS API debug" - default "n" - help - Enabling this option will print API debug messages to the console. - - config SPIFFS_GC_DBG - bool "Enable SPIFFS Garbage Cleaner debug" - default "n" - help - Enabling this option will print GC debug messages to the console. - - config SPIFFS_CACHE_DBG - bool "Enable SPIFFS Cache debug" - default "n" - depends on SPIFFS_CACHE - help - Enabling this option will print cache debug messages to the console. - - config SPIFFS_CHECK_DBG - bool "Enable SPIFFS Filesystem Check debug" - default "n" - help - Enabling this option will print Filesystem Check debug messages - to the console. - - config SPIFFS_TEST_VISUALISATION - bool "Enable SPIFFS Filesystem Visualization" - default "n" - help - Enable this option to enable SPIFFS_vis function in the API. - - endmenu - -endmenu diff --git a/components/spiffs/esp_spiffs.c b/components/spiffs/esp_spiffs.c deleted file mode 100644 index 5731b322b7aa..000000000000 --- a/components/spiffs/esp_spiffs.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "esp_spiffs.h" -#include "spiffs.h" -#include "spiffs_nucleus.h" -#include "esp_log.h" -#include "esp_partition.h" -#include "spi_flash_mmap.h" -#include "esp_image_format.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include -#include -#include -#include -#include -#include "esp_vfs.h" -#include "esp_err.h" -#include "esp_rom_spiflash.h" - -#include "spiffs_api.h" - -static const char* TAG = "SPIFFS"; - -#ifdef CONFIG_SPIFFS_USE_MTIME -#ifdef CONFIG_SPIFFS_MTIME_WIDE_64_BITS -typedef time_t spiffs_time_t; -#else -typedef unsigned long spiffs_time_t; -#endif -_Static_assert(CONFIG_SPIFFS_META_LENGTH >= sizeof(spiffs_time_t), - "SPIFFS_META_LENGTH size should be >= sizeof(spiffs_time_t)"); -#endif //CONFIG_SPIFFS_USE_MTIME - -_Static_assert(ESP_SPIFFS_PATH_MAX == ESP_VFS_PATH_MAX, - "SPIFFS max path length has to be aligned with the VFS max path length"); - -/** - * @brief SPIFFS DIR structure - */ -typedef struct { - DIR dir; /*!< VFS DIR struct */ - spiffs_DIR d; /*!< SPIFFS DIR struct */ - struct dirent e; /*!< Last open dirent */ - long offset; /*!< Offset of the current dirent */ - char path[SPIFFS_OBJ_NAME_LEN]; /*!< Requested directory name */ -} vfs_spiffs_dir_t; - -static int spiffs_res_to_errno(s32_t fr); -static int vfs_spiffs_open(void* ctx, const char * path, int flags, int mode); -static ssize_t vfs_spiffs_write(void* ctx, int fd, const void * data, size_t size); -static ssize_t vfs_spiffs_read(void* ctx, int fd, void * dst, size_t size); -static int vfs_spiffs_close(void* ctx, int fd); -static off_t vfs_spiffs_lseek(void* ctx, int fd, off_t offset, int mode); -static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st); -#ifdef CONFIG_VFS_SUPPORT_DIR -static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st); -static int vfs_spiffs_unlink(void* ctx, const char *path); -static int vfs_spiffs_link(void* ctx, const char* n1, const char* n2); -static int vfs_spiffs_rename(void* ctx, const char *src, const char *dst); -static DIR* vfs_spiffs_opendir(void* ctx, const char* name); -static int vfs_spiffs_closedir(void* ctx, DIR* pdir); -static struct dirent* vfs_spiffs_readdir(void* ctx, DIR* pdir); -static int vfs_spiffs_readdir_r(void* ctx, DIR* pdir, - struct dirent* entry, struct dirent** out_dirent); -static long vfs_spiffs_telldir(void* ctx, DIR* pdir); -static void vfs_spiffs_seekdir(void* ctx, DIR* pdir, long offset); -static int vfs_spiffs_mkdir(void* ctx, const char* name, mode_t mode); -static int vfs_spiffs_rmdir(void* ctx, const char* name); -static int vfs_spiffs_truncate(void* ctx, const char *path, off_t length); -static int vfs_spiffs_ftruncate(void* ctx, int fd, off_t length); -#ifdef CONFIG_SPIFFS_USE_MTIME -static int vfs_spiffs_utime(void *ctx, const char *path, const struct utimbuf *times); -#endif // CONFIG_SPIFFS_USE_MTIME -#endif // CONFIG_VFS_SUPPORT_DIR -static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file f); -static time_t vfs_spiffs_get_mtime(const spiffs_stat* s); - -static esp_spiffs_t * _efs[CONFIG_SPIFFS_MAX_PARTITIONS]; - -static void esp_spiffs_free(esp_spiffs_t ** efs) -{ - esp_spiffs_t * e = *efs; - if (*efs == NULL) { - return; - } - *efs = NULL; - - if (e->fs) { - SPIFFS_unmount(e->fs); - free(e->fs); - } - vSemaphoreDelete(e->lock); - free(e->fds); - free(e->cache); - free(e->work); - free(e); -} - -static esp_err_t esp_spiffs_by_label(const char* label, int * index){ - int i; - esp_spiffs_t * p; - for (i = 0; i < CONFIG_SPIFFS_MAX_PARTITIONS; i++) { - p = _efs[i]; - if (p) { - if (!label && !p->by_label) { - *index = i; - return ESP_OK; - } - if (label && p->by_label && strncmp(label, p->partition->label, 17) == 0) { - *index = i; - return ESP_OK; - } - } - } - return ESP_ERR_NOT_FOUND; -} - -static esp_err_t esp_spiffs_get_empty(int * index){ - int i; - for (i = 0; i < CONFIG_SPIFFS_MAX_PARTITIONS; i++) { - if (_efs[i] == NULL) { - *index = i; - return ESP_OK; - } - } - return ESP_ERR_NOT_FOUND; -} - -static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf) -{ - int index; - //find if such partition is already mounted - if (esp_spiffs_by_label(conf->partition_label, &index) == ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - - if (esp_spiffs_get_empty(&index) != ESP_OK) { - ESP_LOGE(TAG, "max mounted partitions reached"); - return ESP_ERR_INVALID_STATE; - } - - uint32_t flash_page_size = g_rom_flashchip.page_size; - uint32_t log_page_size = CONFIG_SPIFFS_PAGE_SIZE; - if (log_page_size % flash_page_size != 0) { - ESP_LOGE(TAG, "SPIFFS_PAGE_SIZE is not multiple of flash chip page size (%" PRIu32 ")", - flash_page_size); - return ESP_ERR_INVALID_ARG; - } - - esp_partition_subtype_t subtype = conf->partition_label ? - ESP_PARTITION_SUBTYPE_ANY : ESP_PARTITION_SUBTYPE_DATA_SPIFFS; - const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, - subtype, conf->partition_label); - if (!partition) { - ESP_LOGE(TAG, "spiffs partition could not be found"); - return ESP_ERR_NOT_FOUND; - } - - if (partition->encrypted) { - ESP_LOGE(TAG, "spiffs can not run on encrypted partition"); - return ESP_ERR_INVALID_STATE; - } - - const size_t flash_erase_sector_size = g_rom_flashchip.sector_size; - - /* Older versions of IDF allowed creating misaligned data partitions. - * This would result in hard-to-diagnose SPIFFS failures due to failing erase operations. - */ - if (partition->address % flash_erase_sector_size != 0) { - ESP_LOGE(TAG, "spiffs partition is not aligned to flash sector size, please check the partition table"); - /* No return intentional to avoid accidentally breaking applications - * which used misaligned read-only SPIFFS partitions. - */ - } - - /* Check if the SPIFFS internal data types are wide enough. - * Casting -1 to the unsigned type produces the maximum value the type can hold. - * All the checks here are based on comments for the said data types in spiffs_config.h. - */ - if (partition->size / flash_erase_sector_size > (spiffs_block_ix) -1) { - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_block_ix type"); - return ESP_ERR_INVALID_ARG; - } - if (partition->size / log_page_size > (spiffs_page_ix) -1) { - /* For 256 byte pages the largest partition is 16MB, but larger partitions can be supported - * by increasing the page size (reducing the number of pages). - */ - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_page_ix type. Please increase CONFIG_SPIFFS_PAGE_SIZE."); - return ESP_ERR_INVALID_ARG; - } - if (2 + 2 * (partition->size / (2 * log_page_size)) > (spiffs_obj_id) -1) { - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_obj_id type. Please increase CONFIG_SPIFFS_PAGE_SIZE."); - return ESP_ERR_INVALID_ARG; - } - if (partition->size / log_page_size - 1 > (spiffs_span_ix) -1) { - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_span_ix type. Please increase CONFIG_SPIFFS_PAGE_SIZE."); - return ESP_ERR_INVALID_ARG; - } - - esp_spiffs_t * efs = calloc(sizeof(esp_spiffs_t), 1); - if (efs == NULL) { - ESP_LOGE(TAG, "esp_spiffs could not be malloced"); - return ESP_ERR_NO_MEM; - } - - efs->cfg.hal_erase_f = spiffs_api_erase; - efs->cfg.hal_read_f = spiffs_api_read; - efs->cfg.hal_write_f = spiffs_api_write; - efs->cfg.log_block_size = flash_erase_sector_size; - efs->cfg.log_page_size = log_page_size; - efs->cfg.phys_addr = 0; - efs->cfg.phys_erase_block = flash_erase_sector_size; - efs->cfg.phys_size = partition->size; - - efs->by_label = conf->partition_label != NULL; - - efs->lock = xSemaphoreCreateMutex(); - if (efs->lock == NULL) { - ESP_LOGE(TAG, "mutex lock could not be created"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - - efs->fds_sz = conf->max_files * sizeof(spiffs_fd); - efs->fds = calloc(efs->fds_sz, 1); - if (efs->fds == NULL) { - ESP_LOGE(TAG, "fd buffer could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - -#if SPIFFS_CACHE - efs->cache_sz = sizeof(spiffs_cache) + conf->max_files * (sizeof(spiffs_cache_page) - + efs->cfg.log_page_size); - efs->cache = calloc(efs->cache_sz, 1); - if (efs->cache == NULL) { - ESP_LOGE(TAG, "cache buffer could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } -#endif - - const uint32_t work_sz = efs->cfg.log_page_size * 2; - efs->work = calloc(work_sz, 1); - if (efs->work == NULL) { - ESP_LOGE(TAG, "work buffer could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - - efs->fs = calloc(sizeof(spiffs), 1); - if (efs->fs == NULL) { - ESP_LOGE(TAG, "spiffs could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - - efs->fs->user_data = (void *)efs; - efs->partition = partition; - - s32_t res = SPIFFS_mount(efs->fs, &efs->cfg, efs->work, efs->fds, efs->fds_sz, - efs->cache, efs->cache_sz, spiffs_api_check); - - if (conf->format_if_mount_failed && res != SPIFFS_OK) { - ESP_LOGW(TAG, "mount failed, %" PRId32 ". formatting...", SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - res = SPIFFS_format(efs->fs); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "format failed, %" PRId32, SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - esp_spiffs_free(&efs); - return ESP_FAIL; - } - res = SPIFFS_mount(efs->fs, &efs->cfg, efs->work, efs->fds, efs->fds_sz, - efs->cache, efs->cache_sz, spiffs_api_check); - } - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "mount failed, %" PRId32, SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - esp_spiffs_free(&efs); - return ESP_FAIL; - } - _efs[index] = efs; - return ESP_OK; -} - -bool esp_spiffs_mounted(const char* partition_label) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return false; - } - return (SPIFFS_mounted(_efs[index]->fs)); -} - -esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - SPIFFS_info(_efs[index]->fs, (uint32_t *)total_bytes, (uint32_t *)used_bytes); - return ESP_OK; -} - -esp_err_t esp_spiffs_check(const char* partition_label) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - if (SPIFFS_check(_efs[index]->fs) != SPIFFS_OK) { - int spiffs_res = SPIFFS_errno(_efs[index]->fs); - ESP_LOGE(TAG, "SPIFFS_check failed (%d)", spiffs_res); - errno = spiffs_res_to_errno(SPIFFS_errno(_efs[index]->fs)); - SPIFFS_clearerr(_efs[index]->fs); - return ESP_FAIL; - } - return ESP_OK; -} - -esp_err_t esp_spiffs_format(const char* partition_label) -{ - bool partition_was_mounted = false; - int index; - /* If the partition is not mounted, need to create SPIFFS structures - * and mount the partition, unmount, format, delete SPIFFS structures. - * See SPIFFS wiki for the reason why. - */ - esp_err_t err = esp_spiffs_by_label(partition_label, &index); - if (err != ESP_OK) { - esp_vfs_spiffs_conf_t conf = { - .format_if_mount_failed = true, - .partition_label = partition_label, - .max_files = 1 - }; - err = esp_spiffs_init(&conf); - if (err != ESP_OK) { - return err; - } - err = esp_spiffs_by_label(partition_label, &index); - assert(err == ESP_OK && "failed to get index of the partition just mounted"); - } else if (SPIFFS_mounted(_efs[index]->fs)) { - partition_was_mounted = true; - } - - SPIFFS_unmount(_efs[index]->fs); - - s32_t res = SPIFFS_format(_efs[index]->fs); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "format failed, %" PRId32, SPIFFS_errno(_efs[index]->fs)); - SPIFFS_clearerr(_efs[index]->fs); - /* If the partition was previously mounted, but format failed, don't - * try to mount the partition back (it will probably fail). On the - * other hand, if it was not mounted, need to clean up. - */ - if (!partition_was_mounted) { - esp_spiffs_free(&_efs[index]); - } - return ESP_FAIL; - } - - if (partition_was_mounted) { - res = SPIFFS_mount(_efs[index]->fs, &_efs[index]->cfg, _efs[index]->work, - _efs[index]->fds, _efs[index]->fds_sz, _efs[index]->cache, - _efs[index]->cache_sz, spiffs_api_check); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "mount failed, %" PRId32, SPIFFS_errno(_efs[index]->fs)); - SPIFFS_clearerr(_efs[index]->fs); - return ESP_FAIL; - } - } else { - esp_spiffs_free(&_efs[index]); - } - return ESP_OK; -} - -esp_err_t esp_spiffs_gc(const char* partition_label, size_t size_to_gc) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - int res = SPIFFS_gc(_efs[index]->fs, size_to_gc); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "SPIFFS_gc failed, %d", res); - SPIFFS_clearerr(_efs[index]->fs); - if (res == SPIFFS_ERR_FULL) { - return ESP_ERR_NOT_FINISHED; - } - return ESP_FAIL; - } - return ESP_OK; -} - -esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf) -{ - assert(conf->base_path); - - esp_err_t err = esp_spiffs_init(conf); - if (err != ESP_OK) { - return err; - } - - int index; - if (esp_spiffs_by_label(conf->partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - - int vfs_flags = ESP_VFS_FLAG_CONTEXT_PTR; - if (_efs[index]->partition->readonly) { - vfs_flags |= ESP_VFS_FLAG_READONLY_FS; - } - - const esp_vfs_t vfs = { - .flags = vfs_flags, - .write_p = &vfs_spiffs_write, - .lseek_p = &vfs_spiffs_lseek, - .read_p = &vfs_spiffs_read, - .open_p = &vfs_spiffs_open, - .close_p = &vfs_spiffs_close, - .fstat_p = &vfs_spiffs_fstat, -#ifdef CONFIG_VFS_SUPPORT_DIR - .stat_p = &vfs_spiffs_stat, - .link_p = &vfs_spiffs_link, - .unlink_p = &vfs_spiffs_unlink, - .rename_p = &vfs_spiffs_rename, - .opendir_p = &vfs_spiffs_opendir, - .closedir_p = &vfs_spiffs_closedir, - .readdir_p = &vfs_spiffs_readdir, - .readdir_r_p = &vfs_spiffs_readdir_r, - .seekdir_p = &vfs_spiffs_seekdir, - .telldir_p = &vfs_spiffs_telldir, - .mkdir_p = &vfs_spiffs_mkdir, - .rmdir_p = &vfs_spiffs_rmdir, - .truncate_p = &vfs_spiffs_truncate, - .ftruncate_p = &vfs_spiffs_ftruncate, -#ifdef CONFIG_SPIFFS_USE_MTIME - .utime_p = &vfs_spiffs_utime, -#else - .utime_p = NULL, -#endif // CONFIG_SPIFFS_USE_MTIME -#endif // CONFIG_VFS_SUPPORT_DIR - }; - - strlcat(_efs[index]->base_path, conf->base_path, ESP_VFS_PATH_MAX + 1); - err = esp_vfs_register(conf->base_path, &vfs, _efs[index]); - if (err != ESP_OK) { - esp_spiffs_free(&_efs[index]); - return err; - } - - return ESP_OK; -} - -esp_err_t esp_vfs_spiffs_unregister(const char* partition_label) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - esp_err_t err = esp_vfs_unregister(_efs[index]->base_path); - if (err != ESP_OK) { - return err; - } - esp_spiffs_free(&_efs[index]); - return ESP_OK; -} - -static int spiffs_res_to_errno(s32_t fr) -{ - switch(fr) { - case SPIFFS_OK : - return 0; - case SPIFFS_ERR_NOT_MOUNTED : - return ENODEV; - case SPIFFS_ERR_NOT_A_FS : - return ENODEV; - case SPIFFS_ERR_FULL : - return ENOSPC; - case SPIFFS_ERR_BAD_DESCRIPTOR : - return EBADF; - case SPIFFS_ERR_MOUNTED : - return EEXIST; - case SPIFFS_ERR_FILE_EXISTS : - return EEXIST; - case SPIFFS_ERR_NOT_FOUND : - return ENOENT; - case SPIFFS_ERR_NOT_A_FILE : - return ENOENT; - case SPIFFS_ERR_DELETED : - return ENOENT; - case SPIFFS_ERR_FILE_DELETED : - return ENOENT; - case SPIFFS_ERR_NAME_TOO_LONG : - return ENAMETOOLONG; - case SPIFFS_ERR_RO_NOT_IMPL : - return EROFS; - case SPIFFS_ERR_RO_ABORTED_OPERATION : - return EROFS; - default : - return EIO; - } - return ENOTSUP; -} - -static int spiffs_mode_conv(int m) -{ - int res = 0; - int acc_mode = m & O_ACCMODE; - if (acc_mode == O_RDONLY) { - res |= SPIFFS_O_RDONLY; - } else if (acc_mode == O_WRONLY) { - res |= SPIFFS_O_WRONLY; - } else if (acc_mode == O_RDWR) { - res |= SPIFFS_O_RDWR; - } - if ((m & O_CREAT) && (m & O_EXCL)) { - res |= SPIFFS_O_CREAT | SPIFFS_O_EXCL; - } else if ((m & O_CREAT) && (m & O_TRUNC)) { - res |= SPIFFS_O_CREAT | SPIFFS_O_TRUNC; - } - if (m & O_APPEND) { - res |= SPIFFS_O_CREAT | SPIFFS_O_APPEND; - } - return res; -} - -static int vfs_spiffs_open(void* ctx, const char * path, int flags, int mode) -{ - assert(path); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int spiffs_flags = spiffs_mode_conv(flags); - int fd = SPIFFS_open(efs->fs, path, spiffs_flags, mode); - if (fd < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - if (!(spiffs_flags & SPIFFS_RDONLY)) { - vfs_spiffs_update_mtime(efs->fs, fd); - } - return fd; -} - -static ssize_t vfs_spiffs_write(void* ctx, int fd, const void * data, size_t size) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - ssize_t res = SPIFFS_write(efs->fs, fd, (void *)data, size); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static ssize_t vfs_spiffs_read(void* ctx, int fd, void * dst, size_t size) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - ssize_t res = SPIFFS_read(efs->fs, fd, dst, size); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_close(void* ctx, int fd) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_close(efs->fs, fd); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static off_t vfs_spiffs_lseek(void* ctx, int fd, off_t offset, int mode) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - off_t res = SPIFFS_lseek(efs->fs, fd, offset, mode); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st) -{ - assert(st); - spiffs_stat s; - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - off_t res = SPIFFS_fstat(efs->fs, fd, &s); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - memset(st, 0, sizeof(*st)); - st->st_size = s.size; - st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG; - st->st_mtime = vfs_spiffs_get_mtime(&s); - st->st_atime = 0; - st->st_ctime = 0; - return res; -} - -#ifdef CONFIG_VFS_SUPPORT_DIR - -static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st) -{ - assert(path); - assert(st); - spiffs_stat s; - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - off_t res = SPIFFS_stat(efs->fs, path, &s); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - memset(st, 0, sizeof(*st)); - st->st_size = s.size; - st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO; - st->st_mode |= (s.type == SPIFFS_TYPE_DIR)?S_IFDIR:S_IFREG; - st->st_mtime = vfs_spiffs_get_mtime(&s); - st->st_atime = 0; - st->st_ctime = 0; - return res; -} - -static int vfs_spiffs_rename(void* ctx, const char *src, const char *dst) -{ - assert(src); - assert(dst); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_rename(efs->fs, src, dst); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_unlink(void* ctx, const char *path) -{ - assert(path); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_remove(efs->fs, path); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static DIR* vfs_spiffs_opendir(void* ctx, const char* name) -{ - assert(name); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = calloc(1, sizeof(vfs_spiffs_dir_t)); - if (!dir) { - errno = ENOMEM; - return NULL; - } - if (!SPIFFS_opendir(efs->fs, name, &dir->d)) { - free(dir); - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return NULL; - } - dir->offset = 0; - strlcpy(dir->path, name, SPIFFS_OBJ_NAME_LEN); - return (DIR*) dir; -} - -static int vfs_spiffs_closedir(void* ctx, DIR* pdir) -{ - assert(pdir); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - int res = SPIFFS_closedir(&dir->d); - free(dir); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static struct dirent* vfs_spiffs_readdir(void* ctx, DIR* pdir) -{ - assert(pdir); - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - struct dirent* out_dirent; - int err = vfs_spiffs_readdir_r(ctx, pdir, &dir->e, &out_dirent); - if (err != 0) { - errno = err; - return NULL; - } - return out_dirent; -} - -static int vfs_spiffs_readdir_r(void* ctx, DIR* pdir, struct dirent* entry, - struct dirent** out_dirent) -{ - assert(pdir); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - struct spiffs_dirent out; - size_t plen; - char * item_name; - do { - if (SPIFFS_readdir(&dir->d, &out) == 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - if (!errno) { - *out_dirent = NULL; - } - return errno; - } - item_name = (char *)out.name; - plen = strlen(dir->path); - - } while ((plen > 1) && (strncasecmp(dir->path, (const char*)out.name, plen) || out.name[plen] != '/' || !out.name[plen + 1])); - - if (plen > 1) { - item_name += plen + 1; - } else if (item_name[0] == '/') { - item_name++; - } - entry->d_ino = 0; - entry->d_type = out.type; - strncpy(entry->d_name, item_name, SPIFFS_OBJ_NAME_LEN); - entry->d_name[SPIFFS_OBJ_NAME_LEN - 1] = '\0'; - dir->offset++; - *out_dirent = entry; - return 0; -} - -static long vfs_spiffs_telldir(void* ctx, DIR* pdir) -{ - assert(pdir); - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - return dir->offset; -} - -static void vfs_spiffs_seekdir(void* ctx, DIR* pdir, long offset) -{ - assert(pdir); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - struct spiffs_dirent tmp; - if (offset < dir->offset) { - //rewind dir - SPIFFS_closedir(&dir->d); - if (!SPIFFS_opendir(efs->fs, NULL, &dir->d)) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return; - } - dir->offset = 0; - } - while (dir->offset < offset) { - if (SPIFFS_readdir(&dir->d, &tmp) == 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return; - } - size_t plen = strlen(dir->path); - if (plen > 1) { - if (strncasecmp(dir->path, (const char *)tmp.name, plen) || tmp.name[plen] != '/' || !tmp.name[plen+1]) { - continue; - } - } - dir->offset++; - } -} - -static int vfs_spiffs_mkdir(void* ctx, const char* name, mode_t mode) -{ - errno = ENOTSUP; - return -1; -} - -static int vfs_spiffs_rmdir(void* ctx, const char* name) -{ - errno = ENOTSUP; - return -1; -} - -static int vfs_spiffs_truncate(void* ctx, const char *path, off_t length) -{ - assert(path); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int fd = SPIFFS_open(efs->fs, path, SPIFFS_WRONLY, 0); - if (fd < 0) { - goto err; - } - - int res = SPIFFS_ftruncate(efs->fs, fd, length); - if (res < 0) { - (void)SPIFFS_close(efs->fs, fd); - goto err; - } - - res = SPIFFS_close(efs->fs, fd); - if (res < 0) { - goto err; - } - return res; -err: - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; -} - -static int vfs_spiffs_ftruncate(void* ctx, int fd, off_t length) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_ftruncate(efs->fs, fd, length); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_link(void* ctx, const char* n1, const char* n2) -{ - errno = ENOTSUP; - return -1; -} - -#ifdef CONFIG_SPIFFS_USE_MTIME -static int vfs_spiffs_update_mtime_value(spiffs *fs, const char *path, spiffs_time_t t) -{ - int ret = SPIFFS_OK; - spiffs_stat s; - if (CONFIG_SPIFFS_META_LENGTH > sizeof(t)) { - ret = SPIFFS_stat(fs, path, &s); - } - if (ret == SPIFFS_OK) { - memcpy(s.meta, &t, sizeof(t)); - ret = SPIFFS_update_meta(fs, path, s.meta); - } - if (ret != SPIFFS_OK) { - ESP_LOGW(TAG, "Failed to update mtime (%d)", ret); - } - return ret; -} -#endif //CONFIG_SPIFFS_USE_MTIME - -#ifdef CONFIG_SPIFFS_USE_MTIME -static int vfs_spiffs_utime(void *ctx, const char *path, const struct utimbuf *times) -{ - assert(path); - - esp_spiffs_t *efs = (esp_spiffs_t *) ctx; - spiffs_time_t t; - - if (times) { - t = (spiffs_time_t)times->modtime; - } else { - // use current time - t = (spiffs_time_t)time(NULL); - } - - int ret = vfs_spiffs_update_mtime_value(efs->fs, path, t); - - if (ret != SPIFFS_OK) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - - return 0; -} -#endif //CONFIG_SPIFFS_USE_MTIME - -#endif // CONFIG_VFS_SUPPORT_DIR - -static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file fd) -{ -#ifdef CONFIG_SPIFFS_USE_MTIME - spiffs_time_t t = (spiffs_time_t)time(NULL); - spiffs_stat s; - int ret = SPIFFS_OK; - if (CONFIG_SPIFFS_META_LENGTH > sizeof(t)) { - ret = SPIFFS_fstat(fs, fd, &s); - } - if (ret == SPIFFS_OK) { - memcpy(s.meta, &t, sizeof(t)); - ret = SPIFFS_fupdate_meta(fs, fd, s.meta); - } - if (ret != SPIFFS_OK) { - ESP_LOGW(TAG, "Failed to update mtime (%d)", ret); - } -#endif //CONFIG_SPIFFS_USE_MTIME -} - -static time_t vfs_spiffs_get_mtime(const spiffs_stat* s) -{ -#ifdef CONFIG_SPIFFS_USE_MTIME - spiffs_time_t t = 0; - memcpy(&t, s->meta, sizeof(t)); -#else - time_t t = 0; -#endif - return (time_t)t; -} diff --git a/components/spiffs/host_test/.build-test-rules.yml b/components/spiffs/host_test/.build-test-rules.yml deleted file mode 100644 index 9de36c5b1159..000000000000 --- a/components/spiffs/host_test/.build-test-rules.yml +++ /dev/null @@ -1,9 +0,0 @@ -components/spiffs/host_test: - enable: - - if: IDF_TARGET == "linux" - reason: only test on linux - depends_components: - - spi_flash - - esp_partition - - spiffs - - vfs diff --git a/components/spiffs/host_test/CMakeLists.txt b/components/spiffs/host_test/CMakeLists.txt deleted file mode 100644 index 521c80b60d3c..000000000000 --- a/components/spiffs/host_test/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(COMPONENTS main) -# Freertos is included via common components, however, currently only the mock component is compatible with linux -# target. -list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/") - -project(host_test_spiffs) - -# Custom procedure to build/clean image.bin -add_custom_target(image.bin) - -# Expand image.bin to the same size as "spiffs" partition in partition_table.csv - 2*1024*1024 = 2097152 = 2M -add_custom_command( - TARGET image.bin - POST_BUILD - COMMAND python ../../spiffsgen.py 2097152 ../../spiffs ${build_dir}/image.bin -) - -set_property( - DIRECTORY - APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${build_dir}/image.bin") - - -add_dependencies(host_test_spiffs.elf image.bin) diff --git a/components/spiffs/host_test/README.md b/components/spiffs/host_test/README.md deleted file mode 100644 index a545955fa399..000000000000 --- a/components/spiffs/host_test/README.md +++ /dev/null @@ -1,17 +0,0 @@ -| Supported Targets | Linux | -| ----------------- | ----- | - -This is a test project for spiffs-related APIs on Linux target (CONFIG_IDF_TARGET_LINUX). - -# Build -Source the IDF environment as usual. - -Once this is done, build the application: -```bash -idf.py build -``` - -# Run -```bash -idf.py monitor -``` diff --git a/components/spiffs/host_test/main/CMakeLists.txt b/components/spiffs/host_test/main/CMakeLists.txt deleted file mode 100644 index 9e7cfedc7595..000000000000 --- a/components/spiffs/host_test/main/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -idf_component_register(SRCS "host_test_spiffs.c" - PRIV_INCLUDE_DIRS "../.." "../../spiffs/src" - REQUIRES spiffs unity) - -# set BUILD_DIR because test uses a file created in the build directory -target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"") diff --git a/components/spiffs/host_test/main/host_test_spiffs.c b/components/spiffs/host_test/main/host_test_spiffs.c deleted file mode 100644 index a16a0256a694..000000000000 --- a/components/spiffs/host_test/main/host_test_spiffs.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Mockqueue.h" - -#include "esp_partition.h" -#include "spiffs.h" -#include "spiffs_nucleus.h" -#include "spiffs_api.h" - -#include "unity.h" -#include "unity_fixture.h" - -TEST_GROUP(spiffs); - -TEST_SETUP(spiffs) -{ - // CMock init for spiffs xSemaphore* use - xQueueSemaphoreTake_IgnoreAndReturn(0); - xQueueGenericSend_IgnoreAndReturn(0); -} - -TEST_TEAR_DOWN(spiffs) -{ -} - -static void init_spiffs(spiffs *fs, uint32_t max_files) -{ - spiffs_config cfg = {}; - s32_t spiffs_res; - u32_t flash_sector_size; - - const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "storage"); - TEST_ASSERT_NOT_NULL(partition); - - // Configure objects needed by SPIFFS - esp_spiffs_t *user_data = (esp_spiffs_t *) calloc(1, sizeof(*user_data)); - user_data->partition = partition; - fs->user_data = (void *)user_data; - - flash_sector_size = 4096; - - cfg.hal_erase_f = spiffs_api_erase; - cfg.hal_read_f = spiffs_api_read; - cfg.hal_write_f = spiffs_api_write; - cfg.log_block_size = flash_sector_size; - cfg.log_page_size = CONFIG_SPIFFS_PAGE_SIZE; - cfg.phys_addr = 0; - cfg.phys_erase_block = flash_sector_size; - cfg.phys_size = partition->size; - - uint32_t work_sz = cfg.log_page_size * 2; - uint8_t *work = (uint8_t *) malloc(work_sz); - - uint32_t fds_sz = max_files * sizeof(spiffs_fd); - uint8_t *fds = (uint8_t *) malloc(fds_sz); - -#if CONFIG_SPIFFS_CACHE - uint32_t cache_sz = sizeof(spiffs_cache) + max_files * (sizeof(spiffs_cache_page) - + cfg.log_page_size); - uint8_t *cache = (uint8_t *) malloc(cache_sz); -#else - uint32_t cache_sz = 0; - uint8_t cache = NULL; -#endif - - // Special mounting procedure: mount, format, mount as per - // https://github.com/pellepl/spiffs/wiki/Using-spiffs - spiffs_res = SPIFFS_mount(fs, &cfg, work, fds, fds_sz, - cache, cache_sz, spiffs_api_check); - - if (spiffs_res == SPIFFS_ERR_NOT_A_FS) { - spiffs_res = SPIFFS_format(fs); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - spiffs_res = SPIFFS_mount(fs, &cfg, work, fds, fds_sz, - cache, cache_sz, spiffs_api_check); - } - - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); -} - -static void deinit_spiffs(spiffs *fs) -{ - SPIFFS_unmount(fs); - - free(fs->work); - free(fs->user_data); - free(fs->fd_space); - -#if CONFIG_SPIFFS_CACHE - free(fs->cache); -#endif -} - -static void check_spiffs_files(spiffs *fs, const char *base_path, char *cur_path) -{ - DIR *dir; - struct dirent *entry; - size_t len = strlen(cur_path); - - if (len == 0) { - strcpy(cur_path, base_path); - len = strlen(base_path); - } - - dir = opendir(cur_path); - TEST_ASSERT_TRUE(dir != 0); - - while ((entry = readdir(dir)) != NULL) { - char *name = entry->d_name; - - char path[PATH_MAX] = { 0 }; - - // Read the file from host FS - strcpy(path, cur_path); - strcat(path, "/"); - strcat(path, name); - - struct stat sb; - stat(path, &sb); - if (S_ISDIR(sb.st_mode)) { - if (!strcmp(name, ".") || !strcmp(name, "..")) { - continue; - } - cur_path[len] = '/'; - strcpy(cur_path + len + 1, name); - check_spiffs_files(fs, base_path, cur_path); - cur_path[len] = '\0'; - } else { - FILE *f = fopen(path, "r"); - TEST_ASSERT_NOT_NULL(f); - fseek(f, 0, SEEK_END); - long sz = ftell(f); - fseek(f, 0, SEEK_SET); - - char *f_contents = (char *) malloc(sz); - TEST_ASSERT(fread(f_contents, 1, sz, f) == sz); - fclose(f); - - s32_t spiffs_res; - - // Read the file from SPIFFS - char *spiffs_path = path + strlen(base_path); - spiffs_res = SPIFFS_open(fs, spiffs_path, SPIFFS_RDONLY, 0); - - TEST_ASSERT_TRUE(spiffs_res > SPIFFS_OK); - - spiffs_file fd = spiffs_res; - - spiffs_stat stat; - spiffs_res = SPIFFS_stat(fs, spiffs_path, &stat); - - char *spiffs_f_contents = (char *) malloc(stat.size); - spiffs_res = SPIFFS_read(fs, fd, spiffs_f_contents, stat.size); - TEST_ASSERT_TRUE(spiffs_res == stat.size); - - // Compare the contents - TEST_ASSERT_TRUE(sz == stat.size); - - bool same = memcmp(f_contents, spiffs_f_contents, sz) == 0; - TEST_ASSERT_TRUE(same); - - free(f_contents); - free(spiffs_f_contents); - } - } - closedir(dir); -} - -TEST(spiffs, format_disk_open_file_write_and_read_file) -{ - spiffs fs; - s32_t spiffs_res; - - init_spiffs(&fs, 5); - - // Open test file - spiffs_res = SPIFFS_open(&fs, "test.txt", SPIFFS_O_CREAT | SPIFFS_O_RDWR, 0); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - // Generate data - spiffs_file file = spiffs_res; - - uint32_t data_count = 5000; - uint32_t data_size = data_count * sizeof(uint32_t); - - char *data = (char *) malloc(data_size); - char *read = (char *) malloc(data_size); - - for (uint32_t i = 0; i < data_size; i += sizeof(i)) { - *((uint32_t *)(data + i)) = i; - } - - // Write data to file - spiffs_res = SPIFFS_write(&fs, file, (void *)data, data_size); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - TEST_ASSERT_TRUE(spiffs_res == data_size); - - // Set the file object pointer to the beginning - spiffs_res = SPIFFS_lseek(&fs, file, 0, SPIFFS_SEEK_SET); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - // Read the file - spiffs_res = SPIFFS_read(&fs, file, (void *)read, data_size); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - TEST_ASSERT_TRUE(spiffs_res == data_size); - - // Close the test file - spiffs_res = SPIFFS_close(&fs, file); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - TEST_ASSERT_TRUE(memcmp(data, read, data_size) == 0); - - deinit_spiffs(&fs); - - free(read); - free(data); -} - -TEST(spiffs, can_read_spiffs_image) -{ - spiffs fs; - s32_t spiffs_res; - - const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "storage"); - TEST_ASSERT_NOT_NULL(partition); - - // Write the contents of the image file to partition - FILE *img_file = fopen(BUILD_DIR "/image.bin", "r"); - TEST_ASSERT_NOT_NULL(img_file); - - fseek(img_file, 0, SEEK_END); - long img_size = ftell(img_file); - fseek(img_file, 0, SEEK_SET); - - char *img = (char *) malloc(img_size); - TEST_ASSERT(fread(img, 1, img_size, img_file) == img_size); - fclose(img_file); - TEST_ASSERT_EQUAL(partition->size, img_size); - - esp_partition_erase_range(partition, 0, partition->size); - esp_partition_write(partition, 0, img, img_size); - - free(img); - - // Mount the spiffs partition and init filesystem, using the contents of - // the image file - init_spiffs(&fs, 1024); - - // Check spiffs consistency - spiffs_res = SPIFFS_check(&fs); - TEST_ASSERT_TRUE(spiffs_res == SPIFFS_OK); - - char path_buf[PATH_MAX] = {0}; - - // The image is created from the spiffs source directory. Compare the files in that - // directory to the files read from the SPIFFS image. - check_spiffs_files(&fs, BUILD_DIR "/../../spiffs", path_buf); - - deinit_spiffs(&fs); -} - -TEST_GROUP_RUNNER(spiffs) -{ - RUN_TEST_CASE(spiffs, format_disk_open_file_write_and_read_file); - RUN_TEST_CASE(spiffs, can_read_spiffs_image); -} - -static void run_all_tests(void) -{ - RUN_TEST_GROUP(spiffs); -} - -int main(int argc, char **argv) -{ - UNITY_MAIN_FUNC(run_all_tests); - return 0; -} diff --git a/components/spiffs/host_test/partition_table.csv b/components/spiffs/host_test/partition_table.csv deleted file mode 100644 index 81487dc1eaf7..000000000000 --- a/components/spiffs/host_test/partition_table.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1M, -storage, data, spiffs, , 2M, diff --git a/components/spiffs/host_test/pytest_spiffs_linux.py b/components/spiffs/host_test/pytest_spiffs_linux.py deleted file mode 100644 index b4719cc5f1bd..000000000000 --- a/components/spiffs/host_test/pytest_spiffs_linux.py +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Unlicense OR CC0-1.0 -import pytest -from pytest_embedded import Dut - - -@pytest.mark.linux -@pytest.mark.host_test -def test_spiffs_linux(dut: Dut) -> None: - dut.expect_unity_test_output(timeout=5) diff --git a/components/spiffs/host_test/sdkconfig.defaults b/components/spiffs/host_test/sdkconfig.defaults deleted file mode 100644 index 6c7916689ee8..000000000000 --- a/components/spiffs/host_test/sdkconfig.defaults +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_IDF_TARGET="linux" -CONFIG_COMPILER_CXX_EXCEPTIONS=y -CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n -CONFIG_UNITY_ENABLE_FIXTURE=y -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table.csv" diff --git a/components/spiffs/include/esp_spiffs.h b/components/spiffs/include/esp_spiffs.h deleted file mode 100644 index 1b59b9cfde07..000000000000 --- a/components/spiffs/include/esp_spiffs.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _ESP_SPIFFS_H_ -#define _ESP_SPIFFS_H_ - -#include -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Configuration structure for esp_vfs_spiffs_register - */ -typedef struct { - const char* base_path; /*!< File path prefix associated with the filesystem. */ - const char* partition_label; /*!< Optional, label of SPIFFS partition to use. If set to NULL, first partition with subtype=spiffs will be used. */ - size_t max_files; /*!< Maximum files that could be open at the same time. */ - bool format_if_mount_failed; /*!< If true, it will format the file system if it fails to mount. */ -} esp_vfs_spiffs_conf_t; - -/** - * Register and mount SPIFFS to VFS with given path prefix. - * - * @param conf Pointer to esp_vfs_spiffs_conf_t configuration structure - * - * @return - * - ESP_OK if success - * - ESP_ERR_NO_MEM if objects could not be allocated - * - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted - * - ESP_ERR_NOT_FOUND if partition for SPIFFS was not found - * - ESP_FAIL if mount or format fails - */ -esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf); - -/** - * Unregister and unmount SPIFFS from VFS - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register. - * - * @return - * - ESP_OK if successful - * - ESP_ERR_INVALID_STATE already unregistered - */ -esp_err_t esp_vfs_spiffs_unregister(const char* partition_label); - -/** - * Check if SPIFFS is mounted - * - * @param partition_label Optional, label of the partition to check. - * If not specified, first partition with subtype=spiffs is used. - * - * @return - * - true if mounted - * - false if not mounted - */ -bool esp_spiffs_mounted(const char* partition_label); - -/** - * Format the SPIFFS partition - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register. - * @return - * - ESP_OK if successful - * - ESP_FAIL on error - */ -esp_err_t esp_spiffs_format(const char* partition_label); - -/** - * Get information for SPIFFS - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register - * @param[out] total_bytes Size of the file system - * @param[out] used_bytes Current used bytes in the file system - * - * @return - * - ESP_OK if success - * - ESP_ERR_INVALID_STATE if not mounted - */ -esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes); - -/** - * Check integrity of SPIFFS - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register - * @return - * - ESP_OK if successful - * - ESP_ERR_INVALID_STATE if not mounted - * - ESP_FAIL on error - */ -esp_err_t esp_spiffs_check(const char* partition_label); - - -/** - * @brief Perform garbage collection in SPIFFS partition - * - * Call this function to run GC and ensure that at least the given amount of - * space is available in the partition. This function will fail with ESP_ERR_NOT_FINISHED - * if it is not possible to reclaim the requested space (that is, not enough free - * or deleted pages in the filesystem). This function will also fail if it fails to - * reclaim the requested space after CONFIG_SPIFFS_GC_MAX_RUNS number of GC iterations. - * On one GC iteration, SPIFFS will erase one logical block (4kB). Therefore the value - * of CONFIG_SPIFFS_GC_MAX_RUNS should be set at least to the maximum expected size_to_gc, - * divided by 4096. For example, if the application expects to make room for a 1MB file and - * calls esp_spiffs_gc(label, 1024 * 1024), CONFIG_SPIFFS_GC_MAX_RUNS should be set to - * at least 256. - * On the other hand, increasing CONFIG_SPIFFS_GC_MAX_RUNS value increases the maximum - * amount of time for which any SPIFFS GC or write operation may potentially block. - * - * @param partition_label Label of the partition to be garbage-collected. - * The partition must be already mounted. - * @param size_to_gc The number of bytes that the GC process should attempt - * to make available. - * @return - * - ESP_OK on success - * - ESP_ERR_NOT_FINISHED if GC fails to reclaim the size given by size_to_gc - * - ESP_ERR_INVALID_STATE if the partition is not mounted - * - ESP_FAIL on all other errors - */ -esp_err_t esp_spiffs_gc(const char* partition_label, size_t size_to_gc); - -#ifdef __cplusplus -} -#endif - -#endif /* _ESP_SPIFFS_H_ */ diff --git a/components/spiffs/include/spiffs_config.h b/components/spiffs/include/spiffs_config.h deleted file mode 100644 index 3281619256ba..000000000000 --- a/components/spiffs/include/spiffs_config.h +++ /dev/null @@ -1,323 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2013-2017 Peter Andersson (pelleplutt1976gmail.com) - * - * SPDX-License-Identifier: MIT - */ -/* - * spiffs_config.h - * - * Created on: Jul 3, 2013 - * Author: petera - */ - -#ifndef SPIFFS_CONFIG_H_ -#define SPIFFS_CONFIG_H_ - -// ----------- 8< ------------ -// Following includes are for the linux test build of spiffs -// These may/should/must be removed/altered/replaced in your target -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "esp_assert.h" - -// compile time switches -#define SPIFFS_TAG "SPIFFS" - -// Set generic spiffs debug output call. -#if CONFIG_SPIFFS_DBG -#define SPIFFS_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_DBG(...) -#endif -#if CONFIG_SPIFFS_API_DBG -#define SPIFFS_API_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_API_DBG(...) -#endif -#if CONFIG_SPIFFS_DBG -#define SPIFFS_GC_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_GC_DBG(...) -#endif -#if CONFIG_SPIFFS_CACHE_DBG -#define SPIFFS_CACHE_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_CACHE_DBG(...) -#endif -#if CONFIG_SPIFFS_CHECK_DBG -#define SPIFFS_CHECK_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_CHECK_DBG(...) -#endif - -// needed types -typedef int32_t s32_t; -typedef uint32_t u32_t; -typedef int16_t s16_t; -typedef uint16_t u16_t; -typedef int8_t s8_t; -typedef uint8_t u8_t; - -struct spiffs_t; -extern void spiffs_api_lock(struct spiffs_t *fs); -extern void spiffs_api_unlock(struct spiffs_t *fs); - -// Defines spiffs debug print formatters -// some general signed number -#define _SPIPRIi "%" PRIdMAX -// address -#define _SPIPRIad "%08x" -// block -#define _SPIPRIbl "%04x" -// page -#define _SPIPRIpg "%04x" -// span index -#define _SPIPRIsp "%04x" -// file descriptor -#define _SPIPRIfd "%d" -// file object id -#define _SPIPRIid "%04x" -// file flags -#define _SPIPRIfl "%02x" - - -// Enable/disable API functions to determine exact number of bytes -// for filedescriptor and cache buffers. Once decided for a configuration, -// this can be disabled to reduce flash. -#define SPIFFS_BUFFER_HELP 0 - -// Enables/disable memory read caching of nucleus file system operations. -// If enabled, memory area must be provided for cache in SPIFFS_mount. -#ifdef CONFIG_SPIFFS_CACHE -#define SPIFFS_CACHE (1) -#else -#define SPIFFS_CACHE (0) -#endif -#if SPIFFS_CACHE -// Enables memory write caching for file descriptors in hydrogen -#ifdef CONFIG_SPIFFS_CACHE_WR -#define SPIFFS_CACHE_WR (1) -#else -#define SPIFFS_CACHE_WR (0) -#endif - -// Enable/disable statistics on caching. Debug/test purpose only. -#ifdef CONFIG_SPIFFS_CACHE_STATS -#define SPIFFS_CACHE_STATS (1) -#else -#define SPIFFS_CACHE_STATS (0) -#endif -#endif - -// Always check header of each accessed page to ensure consistent state. -// If enabled it will increase number of reads, will increase flash. -#ifdef CONFIG_SPIFFS_PAGE_CHECK -#define SPIFFS_PAGE_CHECK (1) -#else -#define SPIFFS_PAGE_CHECK (0) -#endif - -// Define maximum number of gc runs to perform to reach desired free pages. -#define SPIFFS_GC_MAX_RUNS CONFIG_SPIFFS_GC_MAX_RUNS - -// Enable/disable statistics on gc. Debug/test purpose only. -#ifdef CONFIG_SPIFFS_GC_STATS -#define SPIFFS_GC_STATS (1) -#else -#define SPIFFS_GC_STATS (0) -#endif - -// Garbage collecting examines all pages in a block which and sums up -// to a block score. Deleted pages normally gives positive score and -// used pages normally gives a negative score (as these must be moved). -// To have a fair wear-leveling, the erase age is also included in score, -// whose factor normally is the most positive. -// The larger the score, the more likely it is that the block will -// picked for garbage collection. - -// Garbage collecting heuristics - weight used for deleted pages. -#define SPIFFS_GC_HEUR_W_DELET (5) -// Garbage collecting heuristics - weight used for used pages. -#define SPIFFS_GC_HEUR_W_USED (-1) -// Garbage collecting heuristics - weight used for time between -// last erased and erase of this block. -#define SPIFFS_GC_HEUR_W_ERASE_AGE (50) - -// Object name maximum length. Note that this length include the -// zero-termination character, meaning maximum string of characters -// can at most be SPIFFS_OBJ_NAME_LEN - 1. -#define SPIFFS_OBJ_NAME_LEN (CONFIG_SPIFFS_OBJ_NAME_LEN) - -// Maximum length of the metadata associated with an object. -// Setting to non-zero value enables metadata-related API but also -// changes the on-disk format, so the change is not backward-compatible. -// -// Do note: the meta length must never exceed -// logical_page_size - (SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZE) -// -// This is derived from following: -// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) + -// spiffs_object_ix_header fields + at least some LUT entries) -#define SPIFFS_OBJ_META_LEN (CONFIG_SPIFFS_META_LENGTH) -#define SPIFFS_PAGE_EXTRA_SIZE (64) -ESP_STATIC_ASSERT(SPIFFS_OBJ_META_LEN + SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZE - <= CONFIG_SPIFFS_PAGE_SIZE, "SPIFFS_OBJ_META_LEN or SPIFFS_OBJ_NAME_LEN too long"); - -// Size of buffer allocated on stack used when copying data. -// Lower value generates more read/writes. No meaning having it bigger -// than logical page size. -#define SPIFFS_COPY_BUFFER_STACK (256) - -// Enable this to have an identifiable spiffs filesystem. This will look for -// a magic in all sectors to determine if this is a valid spiffs system or -// not on mount point. If not, SPIFFS_format must be called prior to mounting -// again. -#ifdef CONFIG_SPIFFS_USE_MAGIC -#define SPIFFS_USE_MAGIC (1) -#else -#define SPIFFS_USE_MAGIC (0) -#endif - -#if SPIFFS_USE_MAGIC -// Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is -// enabled, the magic will also be dependent on the length of the filesystem. -// For example, a filesystem configured and formatted for 4 megabytes will not -// be accepted for mounting with a configuration defining the filesystem as 2 -// megabytes. -#ifdef CONFIG_SPIFFS_USE_MAGIC_LENGTH -#define SPIFFS_USE_MAGIC_LENGTH (1) -#else -#define SPIFFS_USE_MAGIC_LENGTH (0) -#endif -#endif - -// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level -// These should be defined on a multithreaded system - -// define this to enter a mutex if you're running on a multithreaded system -#define SPIFFS_LOCK(fs) spiffs_api_lock(fs) -// define this to exit a mutex if you're running on a multithreaded system -#define SPIFFS_UNLOCK(fs) spiffs_api_unlock(fs) - -// Enable if only one spiffs instance with constant configuration will exist -// on the target. This will reduce calculations, flash and memory accesses. -// Parts of configuration must be defined below instead of at time of mount. -#define SPIFFS_SINGLETON 0 - -// Enable this if your target needs aligned data for index tables -#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0 - -// Enable this if you want the HAL callbacks to be called with the spiffs struct -#define SPIFFS_HAL_CALLBACK_EXTRA 1 - -// Enable this if you want to add an integer offset to all file handles -// (spiffs_file). This is useful if running multiple instances of spiffs on -// same target, in order to recognise to what spiffs instance a file handle -// belongs. -// NB: This adds config field fh_ix_offset in the configuration struct when -// mounting, which must be defined. -#define SPIFFS_FILEHDL_OFFSET 0 - -// Enable this to compile a read only version of spiffs. -// This will reduce binary size of spiffs. All code comprising modification -// of the file system will not be compiled. Some config will be ignored. -// HAL functions for erasing and writing to spi-flash may be null. Cache -// can be disabled for even further binary size reduction (and ram savings). -// Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL. -// If the file system cannot be mounted due to aborted erase operation and -// SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be -// returned. -// Might be useful for e.g. bootloaders and such. -#define SPIFFS_READ_ONLY 0 - -// Enable this to add a temporal file cache using the fd buffer. -// The effects of the cache is that SPIFFS_open will find the file faster in -// certain cases. It will make it a lot easier for spiffs to find files -// opened frequently, reducing number of readings from the spi flash for -// finding those files. -// This will grow each fd by 6 bytes. If your files are opened in patterns -// with a degree of temporal locality, the system is optimized. -// Examples can be letting spiffs serve web content, where one file is the css. -// The css is accessed for each html file that is opened, meaning it is -// accessed almost every second time a file is opened. Another example could be -// a log file that is often opened, written, and closed. -// The size of the cache is number of given file descriptors, as it piggybacks -// on the fd update mechanism. The cache lives in the closed file descriptors. -// When closed, the fd know the whereabouts of the file. Instead of forgetting -// this, the temporal cache will keep handling updates to that file even if the -// fd is closed. If the file is opened again, the location of the file is found -// directly. If all available descriptors become opened, all cache memory is -// lost. -#define SPIFFS_TEMPORAL_FD_CACHE 1 - -// Temporal file cache hit score. Each time a file is opened, all cached files -// will lose one point. If the opened file is found in cache, that entry will -// gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this -// value for the specific access patterns of the application. However, it must -// be between 1 (no gain for hitting a cached entry often) and 255. -#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4 - -// Enable to be able to map object indices to memory. -// This allows for faster and more deterministic reading if cases of reading -// large files and when changing file offset by seeking around a lot. -// When mapping a file's index, the file system will be scanned for index pages -// and the info will be put in memory provided by user. When reading, the -// memory map can be looked up instead of searching for index pages on the -// medium. This way, user can trade memory against performance. -// Whole, parts of, or future parts not being written yet can be mapped. The -// memory array will be owned by spiffs and updated accordingly during garbage -// collecting or when modifying the indices. The latter is invoked by when the -// file is modified in some way. The index buffer is tied to the file -// descriptor. -#define SPIFFS_IX_MAP 1 - -// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function -// in the api. This function will visualize all filesystem using given printf -// function. -#ifdef CONFIG_SPIFFS_TEST_VISUALISATION -#define SPIFFS_TEST_VISUALISATION 1 -#else -#define SPIFFS_TEST_VISUALISATION 0 -#endif -#if SPIFFS_TEST_VISUALISATION -#ifndef spiffs_printf -#define spiffs_printf(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#endif -// spiffs_printf argument for a free page -#define SPIFFS_TEST_VIS_FREE_STR "_" -// spiffs_printf argument for a deleted page -#define SPIFFS_TEST_VIS_DELE_STR "/" -// spiffs_printf argument for an index page for given object id -#define SPIFFS_TEST_VIS_INDX_STR(id) "i" -// spiffs_printf argument for a data page for given object id -#define SPIFFS_TEST_VIS_DATA_STR(id) "d" -#endif - -// Types depending on configuration such as the amount of flash bytes -// given to spiffs file system in total (spiffs_file_system_size), -// the logical block size (log_block_size), and the logical page size -// (log_page_size) - -// Block index type. Make sure the size of this type can hold -// the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size -typedef u16_t spiffs_block_ix; -// Page index type. Make sure the size of this type can hold -// the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size -typedef u16_t spiffs_page_ix; -// Object id type - most significant bit is reserved for index flag. Make sure the -// size of this type can hold the highest object id on a full system, -// i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2 -typedef u16_t spiffs_obj_id; -// Object span index type. Make sure the size of this type can -// hold the largest possible span index on the system - -// i.e. (spiffs_file_system_size / log_page_size) - 1 -typedef u16_t spiffs_span_ix; - -#endif /* SPIFFS_CONFIG_H_ */ diff --git a/components/spiffs/project_include.cmake b/components/spiffs/project_include.cmake deleted file mode 100644 index c322a64b06d6..000000000000 --- a/components/spiffs/project_include.cmake +++ /dev/null @@ -1,68 +0,0 @@ -# spiffs_create_partition_image -# -# Create a spiffs image of the specified directory on the host during build and optionally -# have the created image flashed using `idf.py flash` -function(spiffs_create_partition_image partition base_dir) - set(options FLASH_IN_PROJECT) - set(multi DEPENDS) - cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}") - - idf_build_get_property(idf_path IDF_PATH) - set(spiffsgen_py ${PYTHON} ${idf_path}/components/spiffs/spiffsgen.py) - - get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE) - - partition_table_get_partition_info(size "--partition-name ${partition}" "size") - partition_table_get_partition_info(offset "--partition-name ${partition}" "offset") - - if("${size}" AND "${offset}") - set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin) - - if(CONFIG_SPIFFS_USE_MAGIC) - set(use_magic "--use-magic") - endif() - - if(CONFIG_SPIFFS_USE_MAGIC_LENGTH) - set(use_magic_len "--use-magic-len") - endif() - - if(CONFIG_SPIFFS_FOLLOW_SYMLINKS) - set(follow_symlinks "--follow-symlinks") - endif() - - # Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for - # contents of the base dir changing. - add_custom_target(spiffs_${partition}_bin ALL - COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file} - --page-size=${CONFIG_SPIFFS_PAGE_SIZE} - --obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN} - --meta-len=${CONFIG_SPIFFS_META_LENGTH} - ${follow_symlinks} - ${use_magic} - ${use_magic_len} - DEPENDS ${arg_DEPENDS} - ) - - set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY - ADDITIONAL_CLEAN_FILES - ${image_file}) - - idf_component_get_property(main_args esptool_py FLASH_ARGS) - idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS) - # Last (optional) parameter is the encryption for the target. In our - # case, spiffs is not encrypt so pass FALSE to the function. - esptool_py_flash_target(${partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT) - esptool_py_flash_to_partition(${partition}-flash "${partition}" "${image_file}") - - add_dependencies(${partition}-flash spiffs_${partition}_bin) - - if(arg_FLASH_IN_PROJECT) - esptool_py_flash_to_partition(flash "${partition}" "${image_file}") - add_dependencies(flash spiffs_${partition}_bin) - endif() - else() - set(message "Failed to create SPIFFS image for partition '${partition}'. " - "Check project configuration if using the correct partition table file.") - fail_at_build_time(spiffs_${partition}_bin "${message}") - endif() -endfunction() diff --git a/components/spiffs/spiffs b/components/spiffs/spiffs deleted file mode 160000 index 0dbb3f71c5f6..000000000000 --- a/components/spiffs/spiffs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0dbb3f71c5f6fae3747a9d935372773762baf852 diff --git a/components/spiffs/spiffs_api.c b/components/spiffs/spiffs_api.c deleted file mode 100644 index 207b7a67d614..000000000000 --- a/components/spiffs/spiffs_api.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "freertos/FreeRTOS.h" -#include "esp_log.h" -#include "esp_partition.h" -#include "esp_spiffs.h" -#include "spiffs_api.h" - -static const char* TAG = "SPIFFS"; - -void spiffs_api_lock(spiffs *fs) -{ - (void) xSemaphoreTake(((esp_spiffs_t *)(fs->user_data))->lock, portMAX_DELAY); -} - -void spiffs_api_unlock(spiffs *fs) -{ - xSemaphoreGive(((esp_spiffs_t *)(fs->user_data))->lock); -} - -s32_t spiffs_api_read(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *dst) -{ - esp_err_t err = esp_partition_read(((esp_spiffs_t *)(fs->user_data))->partition, - addr, dst, size); - if (unlikely(err)) { - ESP_LOGE(TAG, "failed to read addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err); - return -1; - } - return 0; -} - -s32_t spiffs_api_write(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *src) -{ - esp_err_t err = esp_partition_write(((esp_spiffs_t *)(fs->user_data))->partition, - addr, src, size); - if (unlikely(err)) { - ESP_LOGE(TAG, "failed to write addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err); - return -1; - } - return 0; -} - -s32_t spiffs_api_erase(spiffs *fs, uint32_t addr, uint32_t size) -{ - esp_err_t err = esp_partition_erase_range(((esp_spiffs_t *)(fs->user_data))->partition, - addr, size); - if (err) { - ESP_LOGE(TAG, "failed to erase addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err); - return -1; - } - return 0; -} - -void spiffs_api_check(spiffs *fs, spiffs_check_type type, - spiffs_check_report report, uint32_t arg1, uint32_t arg2) -{ - static const char * spiffs_check_type_str[3] = { - "LOOKUP", - "INDEX", - "PAGE" - }; - - static const char * spiffs_check_report_str[7] = { - "PROGRESS", - "ERROR", - "FIX INDEX", - "FIX LOOKUP", - "DELETE ORPHANED INDEX", - "DELETE PAGE", - "DELETE BAD FILE" - }; - - if (report != SPIFFS_CHECK_PROGRESS) { - ESP_LOGE(TAG, "CHECK: type:%s, report:%s, %" PRIx32 ":%" PRIx32, spiffs_check_type_str[type], - spiffs_check_report_str[report], arg1, arg2); - } else { - ESP_LOGV(TAG, "CHECK PROGRESS: report:%s, %" PRIx32 ":%" PRIx32, - spiffs_check_report_str[report], arg1, arg2); - } -} diff --git a/components/spiffs/spiffs_api.h b/components/spiffs/spiffs_api.h deleted file mode 100644 index 512598a7d20a..000000000000 --- a/components/spiffs/spiffs_api.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "spiffs.h" -#include "esp_compiler.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ESP_SPIFFS_PATH_MAX 15 - -/** - * @brief SPIFFS definition structure - */ -typedef struct { - spiffs *fs; /*!< Handle to the underlying SPIFFS */ - SemaphoreHandle_t lock; /*!< FS lock */ - const esp_partition_t* partition; /*!< The partition on which SPIFFS is located */ - char base_path[ESP_SPIFFS_PATH_MAX+1]; /*!< Mount point */ - bool by_label; /*!< Partition was mounted by label */ - spiffs_config cfg; /*!< SPIFFS Mount configuration */ - uint8_t *work; /*!< Work Buffer */ - uint8_t *fds; /*!< File Descriptor Buffer */ - uint32_t fds_sz; /*!< File Descriptor Buffer Length */ - uint8_t *cache; /*!< Cache Buffer */ - uint32_t cache_sz; /*!< Cache Buffer Length */ -} esp_spiffs_t; - -s32_t spiffs_api_read(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *dst); - -s32_t spiffs_api_write(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *src); - -s32_t spiffs_api_erase(spiffs *fs, uint32_t addr, uint32_t size); - -void spiffs_api_check(spiffs *fs, spiffs_check_type type, - spiffs_check_report report, uint32_t arg1, uint32_t arg2); - -#ifdef __cplusplus -} -#endif diff --git a/components/spiffs/spiffsgen.py b/components/spiffs/spiffsgen.py deleted file mode 100755 index c621fe8a1614..000000000000 --- a/components/spiffs/spiffsgen.py +++ /dev/null @@ -1,590 +0,0 @@ -#!/usr/bin/env python -# -# spiffsgen is a tool used to generate a spiffs image from a directory -# -# SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Apache-2.0 -import argparse -import io -import math -import os -import struct - -try: - import typing - - TSP = typing.TypeVar('TSP', bound='SpiffsObjPageWithIdx') - ObjIdsItem = typing.Tuple[int, typing.Type[TSP]] -except ImportError: - pass - - -SPIFFS_PH_FLAG_USED_FINAL_INDEX = 0xF8 -SPIFFS_PH_FLAG_USED_FINAL = 0xFC - -SPIFFS_PH_FLAG_LEN = 1 -SPIFFS_PH_IX_SIZE_LEN = 4 -SPIFFS_PH_IX_OBJ_TYPE_LEN = 1 -SPIFFS_TYPE_FILE = 1 - -# Based on typedefs under spiffs_config.h -SPIFFS_OBJ_ID_LEN = 2 # spiffs_obj_id -SPIFFS_SPAN_IX_LEN = 2 # spiffs_span_ix -SPIFFS_PAGE_IX_LEN = 2 # spiffs_page_ix -SPIFFS_BLOCK_IX_LEN = 2 # spiffs_block_ix - - -class SpiffsBuildConfig(object): - def __init__(self, - page_size, # type: int - page_ix_len, # type: int - block_size, # type: int - block_ix_len, # type: int - meta_len, # type: int - obj_name_len, # type: int - obj_id_len, # type: int - span_ix_len, # type: int - packed, # type: bool - aligned, # type: bool - endianness, # type: str - use_magic, # type: bool - use_magic_len, # type: bool - aligned_obj_ix_tables # type: bool - ): - if block_size % page_size != 0: - raise RuntimeError('block size should be a multiple of page size') - - self.page_size = page_size - self.block_size = block_size - self.obj_id_len = obj_id_len - self.span_ix_len = span_ix_len - self.packed = packed - self.aligned = aligned - self.obj_name_len = obj_name_len - self.meta_len = meta_len - self.page_ix_len = page_ix_len - self.block_ix_len = block_ix_len - self.endianness = endianness - self.use_magic = use_magic - self.use_magic_len = use_magic_len - self.aligned_obj_ix_tables = aligned_obj_ix_tables - - self.PAGES_PER_BLOCK = self.block_size // self.page_size - self.OBJ_LU_PAGES_PER_BLOCK = int(math.ceil(self.block_size / self.page_size * self.obj_id_len / self.page_size)) - self.OBJ_USABLE_PAGES_PER_BLOCK = self.PAGES_PER_BLOCK - self.OBJ_LU_PAGES_PER_BLOCK - - self.OBJ_LU_PAGES_OBJ_IDS_LIM = self.page_size // self.obj_id_len - - self.OBJ_DATA_PAGE_HEADER_LEN = self.obj_id_len + self.span_ix_len + SPIFFS_PH_FLAG_LEN - - pad = 4 - (4 if self.OBJ_DATA_PAGE_HEADER_LEN % 4 == 0 else self.OBJ_DATA_PAGE_HEADER_LEN % 4) - - self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED = self.OBJ_DATA_PAGE_HEADER_LEN + pad - self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED_PAD = pad - self.OBJ_DATA_PAGE_CONTENT_LEN = self.page_size - self.OBJ_DATA_PAGE_HEADER_LEN - - self.OBJ_INDEX_PAGES_HEADER_LEN = (self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED + SPIFFS_PH_IX_SIZE_LEN + - SPIFFS_PH_IX_OBJ_TYPE_LEN + self.obj_name_len + self.meta_len) - if aligned_obj_ix_tables: - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED = (self.OBJ_INDEX_PAGES_HEADER_LEN + SPIFFS_PAGE_IX_LEN - 1) & ~(SPIFFS_PAGE_IX_LEN - 1) - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED_PAD = self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED - self.OBJ_INDEX_PAGES_HEADER_LEN - else: - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED = self.OBJ_INDEX_PAGES_HEADER_LEN - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED_PAD = 0 - - self.OBJ_INDEX_PAGES_OBJ_IDS_HEAD_LIM = (self.page_size - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED) // self.block_ix_len - self.OBJ_INDEX_PAGES_OBJ_IDS_LIM = (self.page_size - self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED) // self.block_ix_len - - -class SpiffsFullError(RuntimeError): - pass - - -class SpiffsPage(object): - _endianness_dict = { - 'little': '<', - 'big': '>' - } - - _len_dict = { - 1: 'B', - 2: 'H', - 4: 'I', - 8: 'Q' - } - - def __init__(self, bix, build_config): # type: (int, SpiffsBuildConfig) -> None - self.build_config = build_config - self.bix = bix - - def to_binary(self): # type: () -> bytes - raise NotImplementedError() - - -class SpiffsObjPageWithIdx(SpiffsPage): - def __init__(self, obj_id, build_config): # type: (int, SpiffsBuildConfig) -> None - super(SpiffsObjPageWithIdx, self).__init__(0, build_config) - self.obj_id = obj_id - - def to_binary(self): # type: () -> bytes - raise NotImplementedError() - - -class SpiffsObjLuPage(SpiffsPage): - def __init__(self, bix, build_config): # type: (int, SpiffsBuildConfig) -> None - SpiffsPage.__init__(self, bix, build_config) - - self.obj_ids_limit = self.build_config.OBJ_LU_PAGES_OBJ_IDS_LIM - self.obj_ids = list() # type: typing.List[ObjIdsItem] - - def _calc_magic(self, blocks_lim): # type: (int) -> int - # Calculate the magic value mirroring computation done by the macro SPIFFS_MAGIC defined in - # spiffs_nucleus.h - magic = 0x20140529 ^ self.build_config.page_size - if self.build_config.use_magic_len: - magic = magic ^ (blocks_lim - self.bix) - # narrow the result to build_config.obj_id_len bytes - mask = (2 << (8 * self.build_config.obj_id_len)) - 1 - return magic & mask - - def register_page(self, page): # type: (TSP) -> None - if not self.obj_ids_limit > 0: - raise SpiffsFullError() - - obj_id = (page.obj_id, page.__class__) - self.obj_ids.append(obj_id) - self.obj_ids_limit -= 1 - - def to_binary(self): # type: () -> bytes - img = b'' - - for (obj_id, page_type) in self.obj_ids: - if page_type == SpiffsObjIndexPage: - obj_id ^= (1 << ((self.build_config.obj_id_len * 8) - 1)) - img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.obj_id_len], obj_id) - - assert len(img) <= self.build_config.page_size - - img += b'\xFF' * (self.build_config.page_size - len(img)) - - return img - - def magicfy(self, blocks_lim): # type: (int) -> None - # Only use magic value if no valid obj id has been written to the spot, which is the - # spot taken up by the last obj id on last lookup page. The parent is responsible - # for determining which is the last lookup page and calling this function. - remaining = self.obj_ids_limit - empty_obj_id_dict = { - 1: 0xFF, - 2: 0xFFFF, - 4: 0xFFFFFFFF, - 8: 0xFFFFFFFFFFFFFFFF - } - if remaining >= 2: - for i in range(remaining): - if i == remaining - 2: - self.obj_ids.append((self._calc_magic(blocks_lim), SpiffsObjDataPage)) - break - else: - self.obj_ids.append((empty_obj_id_dict[self.build_config.obj_id_len], SpiffsObjDataPage)) - self.obj_ids_limit -= 1 - - -class SpiffsObjIndexPage(SpiffsObjPageWithIdx): - def __init__(self, obj_id, span_ix, size, name, build_config - ): # type: (int, int, int, str, SpiffsBuildConfig) -> None - super(SpiffsObjIndexPage, self).__init__(obj_id, build_config) - self.span_ix = span_ix - self.name = name - self.size = size - - if self.span_ix == 0: - self.pages_lim = self.build_config.OBJ_INDEX_PAGES_OBJ_IDS_HEAD_LIM - else: - self.pages_lim = self.build_config.OBJ_INDEX_PAGES_OBJ_IDS_LIM - - self.pages = list() # type: typing.List[int] - - def register_page(self, page): # type: (SpiffsObjDataPage) -> None - if not self.pages_lim > 0: - raise SpiffsFullError - - self.pages.append(page.offset) - self.pages_lim -= 1 - - def to_binary(self): # type: () -> bytes - obj_id = self.obj_id ^ (1 << ((self.build_config.obj_id_len * 8) - 1)) - img = struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.obj_id_len] + - SpiffsPage._len_dict[self.build_config.span_ix_len] + - SpiffsPage._len_dict[SPIFFS_PH_FLAG_LEN], - obj_id, - self.span_ix, - SPIFFS_PH_FLAG_USED_FINAL_INDEX) - - # Add padding before the object index page specific information - img += b'\xFF' * self.build_config.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED_PAD - - # If this is the first object index page for the object, add filename, type - # and size information - if self.span_ix == 0: - img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[SPIFFS_PH_IX_SIZE_LEN] + - SpiffsPage._len_dict[SPIFFS_PH_FLAG_LEN], - self.size, - SPIFFS_TYPE_FILE) - - img += self.name.encode() + (b'\x00' * ( - (self.build_config.obj_name_len - len(self.name)) - + self.build_config.meta_len - + self.build_config.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED_PAD)) - - # Finally, add the page index of data pages - for page in self.pages: - page = page >> int(math.log(self.build_config.page_size, 2)) - img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.page_ix_len], page) - - assert len(img) <= self.build_config.page_size - - img += b'\xFF' * (self.build_config.page_size - len(img)) - - return img - - -class SpiffsObjDataPage(SpiffsObjPageWithIdx): - def __init__(self, offset, obj_id, span_ix, contents, build_config - ): # type: (int, int, int, bytes, SpiffsBuildConfig) -> None - super(SpiffsObjDataPage, self).__init__(obj_id, build_config) - self.span_ix = span_ix - self.contents = contents - self.offset = offset - - def to_binary(self): # type: () -> bytes - img = struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.obj_id_len] + - SpiffsPage._len_dict[self.build_config.span_ix_len] + - SpiffsPage._len_dict[SPIFFS_PH_FLAG_LEN], - self.obj_id, - self.span_ix, - SPIFFS_PH_FLAG_USED_FINAL) - - img += self.contents - - assert len(img) <= self.build_config.page_size - - img += b'\xFF' * (self.build_config.page_size - len(img)) - - return img - - -class SpiffsBlock(object): - def _reset(self): # type: () -> None - self.cur_obj_index_span_ix = 0 - self.cur_obj_data_span_ix = 0 - self.cur_obj_id = 0 - self.cur_obj_idx_page = None # type: typing.Optional[SpiffsObjIndexPage] - - def __init__(self, bix, build_config): # type: (int, SpiffsBuildConfig) -> None - self.build_config = build_config - self.offset = bix * self.build_config.block_size - self.remaining_pages = self.build_config.OBJ_USABLE_PAGES_PER_BLOCK - self.pages = list() # type: typing.List[SpiffsPage] - self.bix = bix - - lu_pages = list() - for i in range(self.build_config.OBJ_LU_PAGES_PER_BLOCK): - page = SpiffsObjLuPage(self.bix, self.build_config) - lu_pages.append(page) - - self.pages.extend(lu_pages) - - self.lu_page_iter = iter(lu_pages) - self.lu_page = next(self.lu_page_iter) - - self._reset() - - def _register_page(self, page): # type: (TSP) -> None - if isinstance(page, SpiffsObjDataPage): - assert self.cur_obj_idx_page is not None - self.cur_obj_idx_page.register_page(page) # can raise SpiffsFullError - - try: - self.lu_page.register_page(page) - except SpiffsFullError: - self.lu_page = next(self.lu_page_iter) - try: - self.lu_page.register_page(page) - except AttributeError: # no next lookup page - # Since the amount of lookup pages is pre-computed at every block instance, - # this should never occur - raise RuntimeError('invalid attempt to add page to a block when there is no more space in lookup') - - self.pages.append(page) - - def begin_obj(self, obj_id, size, name, obj_index_span_ix=0, obj_data_span_ix=0 - ): # type: (int, int, str, int, int) -> None - if not self.remaining_pages > 0: - raise SpiffsFullError() - self._reset() - - self.cur_obj_id = obj_id - self.cur_obj_index_span_ix = obj_index_span_ix - self.cur_obj_data_span_ix = obj_data_span_ix - - page = SpiffsObjIndexPage(obj_id, self.cur_obj_index_span_ix, size, name, self.build_config) - self._register_page(page) - - self.cur_obj_idx_page = page - - self.remaining_pages -= 1 - self.cur_obj_index_span_ix += 1 - - def update_obj(self, contents): # type: (bytes) -> None - if not self.remaining_pages > 0: - raise SpiffsFullError() - page = SpiffsObjDataPage(self.offset + (len(self.pages) * self.build_config.page_size), - self.cur_obj_id, self.cur_obj_data_span_ix, contents, self.build_config) - - self._register_page(page) - - self.cur_obj_data_span_ix += 1 - self.remaining_pages -= 1 - - def end_obj(self): # type: () -> None - self._reset() - - def is_full(self): # type: () -> bool - return self.remaining_pages <= 0 - - def to_binary(self, blocks_lim): # type: (int) -> bytes - img = b'' - - if self.build_config.use_magic: - for (idx, page) in enumerate(self.pages): - if idx == self.build_config.OBJ_LU_PAGES_PER_BLOCK - 1: - assert isinstance(page, SpiffsObjLuPage) - page.magicfy(blocks_lim) - img += page.to_binary() - else: - for page in self.pages: - img += page.to_binary() - - assert len(img) <= self.build_config.block_size - - img += b'\xFF' * (self.build_config.block_size - len(img)) - return img - - -class SpiffsFS(object): - def __init__(self, img_size, build_config): # type: (int, SpiffsBuildConfig) -> None - if img_size % build_config.block_size != 0: - raise RuntimeError('image size should be a multiple of block size') - - self.img_size = img_size - self.build_config = build_config - - self.blocks = list() # type: typing.List[SpiffsBlock] - self.blocks_lim = self.img_size // self.build_config.block_size - self.remaining_blocks = self.blocks_lim - self.cur_obj_id = 1 # starting object id - - def _create_block(self): # type: () -> SpiffsBlock - if self.is_full(): - raise SpiffsFullError('the image size has been exceeded') - - block = SpiffsBlock(len(self.blocks), self.build_config) - self.blocks.append(block) - self.remaining_blocks -= 1 - return block - - def is_full(self): # type: () -> bool - return self.remaining_blocks <= 0 - - def create_file(self, img_path, file_path): # type: (str, str) -> None - if len(img_path) > self.build_config.obj_name_len: - raise RuntimeError("object name '%s' too long" % img_path) - - name = img_path - - with open(file_path, 'rb') as obj: - contents = obj.read() - - stream = io.BytesIO(contents) - - try: - block = self.blocks[-1] - block.begin_obj(self.cur_obj_id, len(contents), name) - except (IndexError, SpiffsFullError): - block = self._create_block() - block.begin_obj(self.cur_obj_id, len(contents), name) - - contents_chunk = stream.read(self.build_config.OBJ_DATA_PAGE_CONTENT_LEN) - - while contents_chunk: - try: - block = self.blocks[-1] - try: - # This can fail because either (1) all the pages in block have been - # used or (2) object index has been exhausted. - block.update_obj(contents_chunk) - except SpiffsFullError: - # If its (1), use the outer exception handler - if block.is_full(): - raise SpiffsFullError - # If its (2), write another object index page - block.begin_obj(self.cur_obj_id, len(contents), name, - obj_index_span_ix=block.cur_obj_index_span_ix, - obj_data_span_ix=block.cur_obj_data_span_ix) - continue - except (IndexError, SpiffsFullError): - # All pages in the block have been exhausted. Create a new block, copying - # the previous state of the block to a new one for the continuation of the - # current object - prev_block = block - block = self._create_block() - block.cur_obj_id = prev_block.cur_obj_id - block.cur_obj_idx_page = prev_block.cur_obj_idx_page - block.cur_obj_data_span_ix = prev_block.cur_obj_data_span_ix - block.cur_obj_index_span_ix = prev_block.cur_obj_index_span_ix - continue - - contents_chunk = stream.read(self.build_config.OBJ_DATA_PAGE_CONTENT_LEN) - - block.end_obj() - - self.cur_obj_id += 1 - - def to_binary(self): # type: () -> bytes - img = b'' - all_blocks = [] - for block in self.blocks: - all_blocks.append(block.to_binary(self.blocks_lim)) - bix = len(self.blocks) - if self.build_config.use_magic: - # Create empty blocks with magic numbers - while self.remaining_blocks > 0: - block = SpiffsBlock(bix, self.build_config) - all_blocks.append(block.to_binary(self.blocks_lim)) - self.remaining_blocks -= 1 - bix += 1 - else: - # Just fill remaining spaces FF's - all_blocks.append(b'\xFF' * (self.img_size - len(all_blocks) * self.build_config.block_size)) - img += b''.join([blk for blk in all_blocks]) - return img - - -class CustomHelpFormatter(argparse.HelpFormatter): - """ - Similar to argparse.ArgumentDefaultsHelpFormatter, except it - doesn't add the default value if "(default:" is already present. - This helps in the case of options with action="store_false", like - --no-magic or --no-magic-len. - """ - def _get_help_string(self, action): # type: (argparse.Action) -> str - if action.help is None: - return '' - if '%(default)' not in action.help and '(default:' not in action.help: - if action.default is not argparse.SUPPRESS: - defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE] - if action.option_strings or action.nargs in defaulting_nargs: - return action.help + ' (default: %(default)s)' - return action.help - - -def main(): # type: () -> None - parser = argparse.ArgumentParser(description='SPIFFS Image Generator', - formatter_class=CustomHelpFormatter) - - parser.add_argument('image_size', - help='Size of the created image') - - parser.add_argument('base_dir', - help='Path to directory from which the image will be created') - - parser.add_argument('output_file', - help='Created image output file path') - - parser.add_argument('--page-size', - help='Logical page size. Set to value same as CONFIG_SPIFFS_PAGE_SIZE.', - type=int, - default=256) - - parser.add_argument('--block-size', - help="Logical block size. Set to the same value as the flash chip's sector size (g_rom_flashchip.sector_size).", - type=int, - default=4096) - - parser.add_argument('--obj-name-len', - help='File full path maximum length. Set to value same as CONFIG_SPIFFS_OBJ_NAME_LEN.', - type=int, - default=32) - - parser.add_argument('--meta-len', - help='File metadata length. Set to value same as CONFIG_SPIFFS_META_LENGTH.', - type=int, - default=4) - - parser.add_argument('--use-magic', - dest='use_magic', - help='Use magic number to create an identifiable SPIFFS image. Specify if CONFIG_SPIFFS_USE_MAGIC.', - action='store_true') - - parser.add_argument('--no-magic', - dest='use_magic', - help='Inverse of --use-magic (default: --use-magic is enabled)', - action='store_false') - - parser.add_argument('--use-magic-len', - dest='use_magic_len', - help='Use position in memory to create different magic numbers for each block. Specify if CONFIG_SPIFFS_USE_MAGIC_LENGTH.', - action='store_true') - - parser.add_argument('--no-magic-len', - dest='use_magic_len', - help='Inverse of --use-magic-len (default: --use-magic-len is enabled)', - action='store_false') - - parser.add_argument('--follow-symlinks', - help='Take into account symbolic links during partition image creation.', - action='store_true') - - parser.add_argument('--big-endian', - help='Specify if the target architecture is big-endian. If not specified, little-endian is assumed.', - action='store_true') - - parser.add_argument('--aligned-obj-ix-tables', - action='store_true', - help='Use aligned object index tables. Specify if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES is set.') - - parser.set_defaults(use_magic=True, use_magic_len=True) - - args = parser.parse_args() - - if not os.path.exists(args.base_dir): - raise RuntimeError('given base directory %s does not exist' % args.base_dir) - - with open(args.output_file, 'wb') as image_file: - image_size = int(args.image_size, 0) - spiffs_build_default = SpiffsBuildConfig(args.page_size, SPIFFS_PAGE_IX_LEN, - args.block_size, SPIFFS_BLOCK_IX_LEN, args.meta_len, - args.obj_name_len, SPIFFS_OBJ_ID_LEN, SPIFFS_SPAN_IX_LEN, - True, True, 'big' if args.big_endian else 'little', - args.use_magic, args.use_magic_len, args.aligned_obj_ix_tables) - - spiffs = SpiffsFS(image_size, spiffs_build_default) - - for root, dirs, files in os.walk(args.base_dir, followlinks=args.follow_symlinks): - for f in files: - full_path = os.path.join(root, f) - spiffs.create_file('/' + os.path.relpath(full_path, args.base_dir).replace('\\', '/'), full_path) - - image = spiffs.to_binary() - - image_file.write(image) - - -if __name__ == '__main__': - main() diff --git a/components/spiffs/test_apps/.build-test-rules.yml b/components/spiffs/test_apps/.build-test-rules.yml deleted file mode 100644 index f3bf52966abf..000000000000 --- a/components/spiffs/test_apps/.build-test-rules.yml +++ /dev/null @@ -1,10 +0,0 @@ -components/spiffs/test_apps: - disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - reason: These chips should be sufficient for test coverage (Xtensa and RISC-V, single and dual core) - - depends_components: - - spi_flash - - esp_partition - - spiffs - - vfs diff --git a/components/spiffs/test_apps/CMakeLists.txt b/components/spiffs/test_apps/CMakeLists.txt deleted file mode 100644 index b11f543b68ba..000000000000 --- a/components/spiffs/test_apps/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# This is the project CMakeLists.txt file for the test subproject -cmake_minimum_required(VERSION 3.16) - -# "Trim" the build. Include the minimal set of components, main, and anything it depends on. -set(COMPONENTS main) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(test_spiffs) diff --git a/components/spiffs/test_apps/README.md b/components/spiffs/test_apps/README.md deleted file mode 100644 index 16fcfff0ebe3..000000000000 --- a/components/spiffs/test_apps/README.md +++ /dev/null @@ -1,32 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | - -This is a test app for spiffs component. - -# Building -Several configurations are provided as `sdkconfig.ci.XXX` and serve as a template. - -## Example with configuration "release" for target ESP32 - -```bash -rm -rf sdkconfig build -idf.py -DIDF_TARGET=esp32 -DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.ci.release" build -``` - -# Running - -To run locally: - -```bash -idf.py flash monitor -``` - -The tests will be executed and the summary will be printed: - -``` ------------------------ -21 Tests 0 Failures 0 Ignored -OK -``` - -Note, when the Python test script is executed in internal CI, it will test each configuration one by one. When executing this script locally, it will use whichever binary is already built and available in `build` directory. diff --git a/components/spiffs/test_apps/main/CMakeLists.txt b/components/spiffs/test_apps/main/CMakeLists.txt deleted file mode 100644 index e01b34ebe7f2..000000000000 --- a/components/spiffs/test_apps/main/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -idf_component_register(SRCS test_spiffs.c - PRIV_INCLUDE_DIRS . - PRIV_REQUIRES spiffs unity vfs - WHOLE_ARCHIVE - ) diff --git a/components/spiffs/test_apps/main/test_spiffs.c b/components/spiffs/test_apps/main/test_spiffs.c deleted file mode 100644 index ed8d85f864bc..000000000000 --- a/components/spiffs/test_apps/main/test_spiffs.c +++ /dev/null @@ -1,928 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "sdkconfig.h" -#include -#include -#include -#include -#include -#include -#include -#include "unity.h" -#include "esp_log.h" -#include "esp_system.h" -#include "esp_vfs.h" -#include "esp_spiffs.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" -#include "esp_partition.h" -#include "esp_random.h" -#include "esp_rom_sys.h" - -const char* spiffs_test_hello_str = "Hello, World!\n"; -const char* spiffs_test_partition_label = "storage"; - -void app_main(void) -{ - unity_run_menu(); -} - -static const esp_partition_t *get_partition(void) -{ - const esp_partition_t *result = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, - ESP_PARTITION_SUBTYPE_DATA_SPIFFS, spiffs_test_partition_label); - TEST_ASSERT_NOT_NULL_MESSAGE(result, "partition table not set correctly"); - return result; -} - -static void test_spiffs_create_file_with_text(const char* name, const char* text) -{ - FILE* f = fopen(name, "wb"); - TEST_ASSERT_NOT_NULL(f); - TEST_ASSERT_TRUE(fputs(text, f) != EOF); - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_overwrite_append(const char* filename) -{ - /* Create new file with 'aaaa' */ - test_spiffs_create_file_with_text(filename, "aaaa"); - - /* Append 'bbbb' to file */ - FILE *f_a = fopen(filename, "a"); - TEST_ASSERT_NOT_NULL(f_a); - TEST_ASSERT_NOT_EQUAL(EOF, fputs("bbbb", f_a)); - TEST_ASSERT_EQUAL(0, fclose(f_a)); - - /* Read back 8 bytes from file, verify it's 'aaaabbbb' */ - char buf[10] = { 0 }; - FILE *f_r = fopen(filename, "r"); - TEST_ASSERT_NOT_NULL(f_r); - TEST_ASSERT_EQUAL(8, fread(buf, 1, 8, f_r)); - TEST_ASSERT_EQUAL_STRING_LEN("aaaabbbb", buf, 8); - - /* Be sure we're at end of file */ - TEST_ASSERT_EQUAL(0, fread(buf, 1, 8, f_r)); - - TEST_ASSERT_EQUAL(0, fclose(f_r)); - - /* Overwrite file with 'cccc' */ - test_spiffs_create_file_with_text(filename, "cccc"); - - /* Verify file now only contains 'cccc' */ - f_r = fopen(filename, "r"); - TEST_ASSERT_NOT_NULL(f_r); - bzero(buf, sizeof(buf)); - TEST_ASSERT_EQUAL(4, fread(buf, 1, 8, f_r)); // trying to read 8 bytes, only expecting 4 - TEST_ASSERT_EQUAL_STRING_LEN("cccc", buf, 4); - TEST_ASSERT_EQUAL(0, fclose(f_r)); -} - -static void test_spiffs_read_file(const char* filename) -{ - FILE* f = fopen(filename, "r"); - TEST_ASSERT_NOT_NULL(f); - char buf[32] = { 0 }; - int cb = fread(buf, 1, sizeof(buf), f); - TEST_ASSERT_EQUAL(strlen(spiffs_test_hello_str), cb); - TEST_ASSERT_EQUAL(0, strcmp(spiffs_test_hello_str, buf)); - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_open_max_files(const char* filename_prefix, size_t files_count) -{ - FILE** files = calloc(files_count, sizeof(FILE*)); - for (size_t i = 0; i < files_count; ++i) { - char name[32]; - snprintf(name, sizeof(name), "%s_%d.txt", filename_prefix, i); - files[i] = fopen(name, "w"); - TEST_ASSERT_NOT_NULL(files[i]); - } - /* close everything and clean up */ - for (size_t i = 0; i < files_count; ++i) { - fclose(files[i]); - } - free(files); -} - -static void test_spiffs_lseek(const char* filename) -{ - FILE* f = fopen(filename, "wb+"); - TEST_ASSERT_NOT_NULL(f); - TEST_ASSERT_EQUAL(11, fprintf(f, "0123456789\n")); - TEST_ASSERT_EQUAL(0, fseek(f, -2, SEEK_CUR)); - TEST_ASSERT_EQUAL('9', fgetc(f)); - TEST_ASSERT_EQUAL(0, fseek(f, 3, SEEK_SET)); - TEST_ASSERT_EQUAL('3', fgetc(f)); - TEST_ASSERT_EQUAL(0, fseek(f, -3, SEEK_END)); - TEST_ASSERT_EQUAL('8', fgetc(f)); - TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_END)); - TEST_ASSERT_EQUAL(11, ftell(f)); - TEST_ASSERT_EQUAL(4, fprintf(f, "abc\n")); - TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_END)); - TEST_ASSERT_EQUAL(15, ftell(f)); - TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_SET)); - char buf[20]; - TEST_ASSERT_EQUAL(15, fread(buf, 1, sizeof(buf), f)); - const char ref_buf[] = "0123456789\nabc\n"; - TEST_ASSERT_EQUAL_INT8_ARRAY(ref_buf, buf, sizeof(ref_buf) - 1); - - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_stat(const char* filename) -{ - test_spiffs_create_file_with_text(filename, "foo\n"); - struct stat st; - TEST_ASSERT_EQUAL(0, stat(filename, &st)); - TEST_ASSERT(st.st_mode & S_IFREG); - TEST_ASSERT_FALSE(st.st_mode & S_IFDIR); -} - -static void test_spiffs_unlink(const char* filename) -{ - test_spiffs_create_file_with_text(filename, "unlink\n"); - - TEST_ASSERT_EQUAL(0, unlink(filename)); - - TEST_ASSERT_NULL(fopen(filename, "r")); -} - -static void test_spiffs_rename(const char* filename_prefix) -{ - char name_dst[64]; - char name_src[64]; - snprintf(name_dst, sizeof(name_dst), "%s_dst.txt", filename_prefix); - snprintf(name_src, sizeof(name_src), "%s_src.txt", filename_prefix); - - unlink(name_dst); - unlink(name_src); - - FILE* f = fopen(name_src, "w+"); - TEST_ASSERT_NOT_NULL(f); - const char* str = "0123456789"; - for (int i = 0; i < 400; ++i) { - TEST_ASSERT_NOT_EQUAL(EOF, fputs(str, f)); - } - TEST_ASSERT_EQUAL(0, fclose(f)); - TEST_ASSERT_EQUAL(0, rename(name_src, name_dst)); - TEST_ASSERT_NULL(fopen(name_src, "r")); - FILE* fdst = fopen(name_dst, "r"); - TEST_ASSERT_NOT_NULL(fdst); - TEST_ASSERT_EQUAL(0, fseek(fdst, 0, SEEK_END)); - TEST_ASSERT_EQUAL(4000, ftell(fdst)); - TEST_ASSERT_EQUAL(0, fclose(fdst)); -} - -static void test_spiffs_truncate(const char *filename) -{ - int read = 0; - int truncated_len = 0; - - const char input[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char output[sizeof(input)]; - - test_spiffs_create_file_with_text(filename, input); - - // Extending file beyond size is not supported - TEST_ASSERT_EQUAL(-1, truncate(filename, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, truncate(filename, -1)); - - // Truncating should succeed - const char truncated_1[] = "ABCDEFGHIJ"; - truncated_len = strlen(truncated_1); - TEST_ASSERT_EQUAL(0, truncate(filename, truncated_len)); - - - FILE* f = fopen(filename, "rb"); - TEST_ASSERT_NOT_NULL(f); - memset(output, 0, sizeof(output)); - read = fread(output, 1, sizeof(output), f); - TEST_ASSERT_EQUAL(truncated_len, read); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_1, output, truncated_len); - TEST_ASSERT_EQUAL(0, fclose(f)); - - // Once truncated, the new file size should be the basis - // whether truncation should succeed or not - TEST_ASSERT_EQUAL(-1, truncate(filename, truncated_len + 1)); - TEST_ASSERT_EQUAL(-1, truncate(filename, strlen(input))); - TEST_ASSERT_EQUAL(-1, truncate(filename, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, truncate(filename, -1)); - - - // Truncating a truncated file should succeed - const char truncated_2[] = "ABCDE"; - truncated_len = strlen(truncated_2); - TEST_ASSERT_EQUAL(0, truncate(filename, truncated_len)); - - f = fopen(filename, "rb"); - TEST_ASSERT_NOT_NULL(f); - memset(output, 0, sizeof(output)); - read = fread(output, 1, sizeof(output), f); - TEST_ASSERT_EQUAL(truncated_len, read); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_2, output, truncated_len); - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_ftruncate(const char *filename) -{ - int truncated_len = 0; - - const char input[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char output[sizeof(input)]; - - int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC); - TEST_ASSERT_NOT_EQUAL(-1, fd); - - TEST_ASSERT_EQUAL(strlen(input), write(fd, input, strlen(input))); - - // Extending file beyond size is not supported - TEST_ASSERT_EQUAL(-1, ftruncate(fd, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, -1)); - - // Truncating should succeed - const char truncated_1[] = "ABCDEFGHIJ"; - truncated_len = strlen(truncated_1); - TEST_ASSERT_EQUAL(0, ftruncate(fd, truncated_len)); - TEST_ASSERT_EQUAL(0, close(fd)); - - fd = open(filename, O_RDONLY); - TEST_ASSERT_NOT_EQUAL(-1, fd); - memset(output, 0, sizeof(output)); - TEST_ASSERT_EQUAL(truncated_len, read(fd, output, sizeof(output))); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_1, output, truncated_len); - TEST_ASSERT_EQUAL(0, close(fd)); - - // further truncate the file - fd = open(filename, O_WRONLY); - TEST_ASSERT_NOT_EQUAL(-1, fd); - // Once truncated, the new file size should be the basis - // whether truncation should succeed or not - TEST_ASSERT_EQUAL(-1, ftruncate(fd, truncated_len + 1)); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, strlen(input))); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, -1)); - - // Truncating a truncated file should succeed - const char truncated_2[] = "ABCDE"; - truncated_len = strlen(truncated_2); - - TEST_ASSERT_EQUAL(0, ftruncate(fd, truncated_len)); - TEST_ASSERT_EQUAL(0, close(fd)); - - // open file for reading and validate the content - fd = open(filename, O_RDONLY); - TEST_ASSERT_NOT_EQUAL(-1, fd); - memset(output, 0, sizeof(output)); - TEST_ASSERT_EQUAL(truncated_len, read(fd, output, sizeof(output))); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_2, output, truncated_len); - TEST_ASSERT_EQUAL(0, close(fd)); -} - -static void test_spiffs_can_opendir(const char* path) -{ - char name_dir_file[64]; - const char * file_name = "test_opd.txt"; - snprintf(name_dir_file, sizeof(name_dir_file), "%s/%s", path, file_name); - unlink(name_dir_file); - test_spiffs_create_file_with_text(name_dir_file, "test_opendir\n"); - DIR* dir = opendir(path); - TEST_ASSERT_NOT_NULL(dir); - bool found = false; - while (true) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - if (strcasecmp(de->d_name, file_name) == 0) { - found = true; - break; - } - } - TEST_ASSERT_TRUE(found); - TEST_ASSERT_EQUAL(0, closedir(dir)); - unlink(name_dir_file); -} - -static void test_spiffs_opendir_readdir_rewinddir(const char* dir_prefix) -{ - char name_dir_inner_file[64]; - char name_dir_inner[64]; - char name_dir_file3[64]; - char name_dir_file2[64]; - char name_dir_file1[64]; - - snprintf(name_dir_inner_file, sizeof(name_dir_inner_file), "%s/inner/3.txt", dir_prefix); - snprintf(name_dir_inner, sizeof(name_dir_inner), "%s/inner", dir_prefix); - snprintf(name_dir_file3, sizeof(name_dir_file2), "%s/boo.bin", dir_prefix); - snprintf(name_dir_file2, sizeof(name_dir_file2), "%s/2.txt", dir_prefix); - snprintf(name_dir_file1, sizeof(name_dir_file1), "%s/1.txt", dir_prefix); - - unlink(name_dir_inner_file); - rmdir(name_dir_inner); - unlink(name_dir_file1); - unlink(name_dir_file2); - unlink(name_dir_file3); - rmdir(dir_prefix); - - test_spiffs_create_file_with_text(name_dir_file1, "1\n"); - test_spiffs_create_file_with_text(name_dir_file2, "2\n"); - test_spiffs_create_file_with_text(name_dir_file3, "\01\02\03"); - test_spiffs_create_file_with_text(name_dir_inner_file, "3\n"); - - DIR* dir = opendir(dir_prefix); - TEST_ASSERT_NOT_NULL(dir); - int count = 0; - const char* names[4]; - while(count < 4) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - printf("found '%s'\n", de->d_name); - if (strcasecmp(de->d_name, "1.txt") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "1.txt"; - ++count; - } else if (strcasecmp(de->d_name, "2.txt") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "2.txt"; - ++count; - } else if (strcasecmp(de->d_name, "inner/3.txt") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "inner/3.txt"; - ++count; - } else if (strcasecmp(de->d_name, "boo.bin") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "boo.bin"; - ++count; - } else { - TEST_FAIL_MESSAGE("unexpected directory entry"); - } - } - TEST_ASSERT_EQUAL(count, 4); - - rewinddir(dir); - struct dirent* de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[0])); - seekdir(dir, 3); - de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[3])); - seekdir(dir, 1); - de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[1])); - seekdir(dir, 2); - de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[2])); - - TEST_ASSERT_EQUAL(0, closedir(dir)); -} - -static void test_spiffs_readdir_many_files(const char* dir_prefix) -{ - const int n_files = 40; - const int n_folders = 4; - unsigned char file_count[n_files * n_folders]; - memset(file_count, 0, sizeof(file_count)/sizeof(file_count[0])); - char file_name[ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN]; - - /* clean stale files before the test */ - DIR* dir = opendir(dir_prefix); - if (dir) { - while (true) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - int len = snprintf(file_name, sizeof(file_name), "%s/%s", dir_prefix, de->d_name); - assert(len < sizeof(file_name)); - unlink(file_name); - } - } - - /* create files */ - for (int d = 0; d < n_folders; ++d) { - printf("filling directory %d\n", d); - for (int f = 0; f < n_files; ++f) { - snprintf(file_name, sizeof(file_name), "%s/%d/%d.txt", dir_prefix, d, f); - test_spiffs_create_file_with_text(file_name, file_name); - } - } - - /* list files */ - for (int d = 0; d < n_folders; ++d) { - printf("listing files in directory %d\n", d); - snprintf(file_name, sizeof(file_name), "%s/%d", dir_prefix, d); - dir = opendir(file_name); - TEST_ASSERT_NOT_NULL(dir); - while (true) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - int file_id; - TEST_ASSERT_EQUAL(1, sscanf(de->d_name, "%d.txt", &file_id)); - file_count[file_id + d * n_files]++; - } - closedir(dir); - } - - /* check that all created files have been seen */ - for (int d = 0; d < n_folders; ++d) { - printf("checking that all files have been found in directory %d\n", d); - for (int f = 0; f < n_files; ++f) { - TEST_ASSERT_EQUAL(1, file_count[f + d * n_files]); - } - } -} - - -typedef struct { - const char* filename; - bool write; - size_t word_count; - int seed; - SemaphoreHandle_t done; - int result; -} read_write_test_arg_t; - -#define READ_WRITE_TEST_ARG_INIT(name, seed_) \ - { \ - .filename = name, \ - .seed = seed_, \ - .word_count = 4096, \ - .write = true, \ - .done = xSemaphoreCreateBinary() \ - } - -static void read_write_task(void* param) -{ - read_write_test_arg_t* args = (read_write_test_arg_t*) param; - FILE* f = fopen(args->filename, args->write ? "wb" : "rb"); - if (f == NULL) { - args->result = ESP_ERR_NOT_FOUND; - goto done; - } - - srand(args->seed); - for (size_t i = 0; i < args->word_count; ++i) { - uint32_t val = rand(); - if (args->write) { - int cnt = fwrite(&val, sizeof(val), 1, f); - if (cnt != 1) { - printf("E(w): i=%d, cnt=%d val=0x%" PRIx32 "\n\n", i, cnt, val); - args->result = ESP_FAIL; - goto close; - } - } else { - uint32_t rval; - int cnt = fread(&rval, sizeof(rval), 1, f); - if (cnt != 1 || rval != val) { - esp_rom_printf("E(r): i=%d, cnt=%d val=0x%" PRIx32 " rval=0x%" PRIx32 "\n\n", i, cnt, rval); - args->result = ESP_FAIL; - goto close; - } - } - } - args->result = ESP_OK; - -close: - fclose(f); - -done: - xSemaphoreGive(args->done); - vTaskDelay(1); - vTaskDelete(NULL); -} - -static void test_spiffs_concurrent(const char* filename_prefix) -{ - char names[4][64]; - for (size_t i = 0; i < 4; ++i) { - snprintf(names[i], sizeof(names[i]), "%s%d", filename_prefix, i + 1); - unlink(names[i]); - } - - read_write_test_arg_t args1 = READ_WRITE_TEST_ARG_INIT(names[0], 1); - read_write_test_arg_t args2 = READ_WRITE_TEST_ARG_INIT(names[1], 2); - - const uint32_t stack_size = 3072; - - printf("writing f1 and f2\n"); - const int cpuid_0 = 0; - const int cpuid_1 = CONFIG_FREERTOS_NUMBER_OF_CORES - 1; - xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, cpuid_0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, cpuid_1); - - xSemaphoreTake(args1.done, portMAX_DELAY); - printf("f1 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args1.result); - xSemaphoreTake(args2.done, portMAX_DELAY); - printf("f2 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args2.result); - - args1.write = false; - args2.write = false; - read_write_test_arg_t args3 = READ_WRITE_TEST_ARG_INIT(names[2], 3); - read_write_test_arg_t args4 = READ_WRITE_TEST_ARG_INIT(names[3], 4); - - printf("reading f1 and f2, writing f3 and f4\n"); - - xTaskCreatePinnedToCore(&read_write_task, "rw3", stack_size, &args3, 3, NULL, cpuid_1); - xTaskCreatePinnedToCore(&read_write_task, "rw4", stack_size, &args4, 3, NULL, cpuid_0); - xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, cpuid_0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, cpuid_1); - - xSemaphoreTake(args1.done, portMAX_DELAY); - printf("f1 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args1.result); - xSemaphoreTake(args2.done, portMAX_DELAY); - printf("f2 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args2.result); - xSemaphoreTake(args3.done, portMAX_DELAY); - printf("f3 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args3.result); - xSemaphoreTake(args4.done, portMAX_DELAY); - printf("f4 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args4.result); - - vSemaphoreDelete(args1.done); - vSemaphoreDelete(args2.done); - vSemaphoreDelete(args3.done); - vSemaphoreDelete(args4.done); -} - - -static void test_setup(void) -{ - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = spiffs_test_partition_label, - .max_files = 5, - .format_if_mount_failed = true - }; - - TEST_ESP_OK(esp_vfs_spiffs_register(&conf)); -} - -static void test_teardown(void) -{ - TEST_ESP_OK(esp_vfs_spiffs_unregister(spiffs_test_partition_label)); -} - -TEST_CASE("can initialize SPIFFS in erased partition", "[spiffs]") -{ - const esp_partition_t* part = get_partition(); - TEST_ASSERT_NOT_NULL(part); - TEST_ESP_OK(esp_partition_erase_range(part, 0, part->size)); - test_setup(); - size_t total = 0, used = 0; - TEST_ESP_OK(esp_spiffs_info(spiffs_test_partition_label, &total, &used)); - printf("total: %d, used: %d\n", total, used); - TEST_ASSERT_EQUAL(0, used); - test_teardown(); -} - -TEST_CASE("can format mounted partition", "[spiffs]") -{ - // Mount SPIFFS, create file, format, check that the file does not exist. - const esp_partition_t* part = get_partition(); - TEST_ASSERT_NOT_NULL(part); - test_setup(); - const char* filename = "/spiffs/hello.txt"; - test_spiffs_create_file_with_text(filename, spiffs_test_hello_str); - esp_spiffs_format(part->label); - FILE* f = fopen(filename, "r"); - TEST_ASSERT_NULL(f); - test_teardown(); -} - -TEST_CASE("can format unmounted partition", "[spiffs]") -{ - // Mount SPIFFS, create file, unmount. Format. Mount again, check that - // the file does not exist. - const esp_partition_t* part = get_partition(); - TEST_ASSERT_NOT_NULL(part); - test_setup(); - const char* filename = "/spiffs/hello.txt"; - test_spiffs_create_file_with_text(filename, spiffs_test_hello_str); - test_teardown(); - esp_spiffs_format(part->label); - // Don't use test_setup here, need to mount without formatting - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = spiffs_test_partition_label, - .max_files = 5, - .format_if_mount_failed = false - }; - TEST_ESP_OK(esp_vfs_spiffs_register(&conf)); - FILE* f = fopen(filename, "r"); - TEST_ASSERT_NULL(f); - test_teardown(); -} - -TEST_CASE("can create and write file", "[spiffs]") -{ - test_setup(); - test_spiffs_create_file_with_text("/spiffs/hello.txt", spiffs_test_hello_str); - test_teardown(); -} - -TEST_CASE("can read file", "[spiffs]") -{ - test_setup(); - test_spiffs_create_file_with_text("/spiffs/hello.txt", spiffs_test_hello_str); - test_spiffs_read_file("/spiffs/hello.txt"); - test_teardown(); -} - -TEST_CASE("can open maximum number of files", "[spiffs]") -{ - size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr */ - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = spiffs_test_partition_label, - .format_if_mount_failed = true, - .max_files = max_files - }; - TEST_ESP_OK(esp_vfs_spiffs_register(&conf)); - test_spiffs_open_max_files("/spiffs/f", max_files); - TEST_ESP_OK(esp_vfs_spiffs_unregister(spiffs_test_partition_label)); -} - -TEST_CASE("overwrite and append file", "[spiffs]") -{ - test_setup(); - test_spiffs_overwrite_append("/spiffs/hello.txt"); - test_teardown(); -} - -TEST_CASE("can lseek", "[spiffs]") -{ - test_setup(); - test_spiffs_lseek("/spiffs/seek.txt"); - test_teardown(); -} - - -TEST_CASE("stat returns correct values", "[spiffs]") -{ - test_setup(); - test_spiffs_stat("/spiffs/stat.txt"); - test_teardown(); -} - -TEST_CASE("unlink removes a file", "[spiffs]") -{ - test_setup(); - test_spiffs_unlink("/spiffs/unlink.txt"); - test_teardown(); -} - -TEST_CASE("rename moves a file", "[spiffs]") -{ - test_setup(); - test_spiffs_rename("/spiffs/move"); - test_teardown(); -} - -TEST_CASE("truncate a file", "[spiffs]") -{ - test_setup(); - test_spiffs_truncate("/spiffs/truncate.txt"); - test_teardown(); -} - -TEST_CASE("ftruncate a file", "[spiffs]") -{ - test_setup(); - test_spiffs_ftruncate("/spiffs/ftrunc.txt"); - test_teardown(); -} - -TEST_CASE("can opendir root directory of FS", "[spiffs]") -{ - test_setup(); - test_spiffs_can_opendir("/spiffs"); - test_teardown(); -} - -TEST_CASE("opendir, readdir, rewinddir, seekdir work as expected", "[spiffs]") -{ - test_setup(); - test_spiffs_opendir_readdir_rewinddir("/spiffs/dir"); - test_teardown(); -} - -TEST_CASE("readdir with large number of files", "[spiffs][timeout=30]") -{ - test_setup(); - test_spiffs_readdir_many_files("/spiffs/dir2"); - test_teardown(); -} - -TEST_CASE("multiple tasks can use same volume", "[spiffs]") -{ - test_setup(); - test_spiffs_concurrent("/spiffs/f"); - test_teardown(); -} - -#ifdef CONFIG_SPIFFS_USE_MTIME -TEST_CASE("mtime is updated when file is opened", "[spiffs]") -{ - /* Open a file, check that mtime is set correctly */ - const char* filename = "/spiffs/time"; - test_setup(); - time_t t_before_create = time(NULL); - test_spiffs_create_file_with_text(filename, "\n"); - time_t t_after_create = time(NULL); - - struct stat st; - TEST_ASSERT_EQUAL(0, stat(filename, &st)); - printf("mtime=%d\n", (int) st.st_mtime); - TEST_ASSERT(st.st_mtime >= t_before_create - && st.st_mtime <= t_after_create); - - /* Wait a bit, open again, check that mtime is updated */ - vTaskDelay(2000 / portTICK_PERIOD_MS); - time_t t_before_open = time(NULL); - FILE *f = fopen(filename, "a"); - time_t t_after_open = time(NULL); - TEST_ASSERT_EQUAL(0, fstat(fileno(f), &st)); - printf("mtime=%d\n", (int) st.st_mtime); - TEST_ASSERT(st.st_mtime >= t_before_open - && st.st_mtime <= t_after_open); - fclose(f); - - /* Wait a bit, open for reading, check that mtime is not updated */ - vTaskDelay(2000 / portTICK_PERIOD_MS); - time_t t_before_open_ro = time(NULL); - f = fopen(filename, "r"); - TEST_ASSERT_EQUAL(0, fstat(fileno(f), &st)); - printf("mtime=%d\n", (int) st.st_mtime); - TEST_ASSERT(t_before_open_ro > t_after_open - && st.st_mtime >= t_before_open - && st.st_mtime <= t_after_open); - fclose(f); - - test_teardown(); -} - -TEST_CASE("utime() works well", "[spiffs]") -{ - const char filename[] = "/spiffs/utime.txt"; - struct stat achieved_stat; - struct tm desired_tm; - struct utimbuf desired_time = { - .actime = 0, // access time is not supported - .modtime = 0, - }; - time_t false_now = 0; - memset(&desired_tm, 0, sizeof(struct tm)); - - test_setup(); - { - // Setting up a false actual time - used when the file is created and for modification with the current time - desired_tm.tm_mon = 10 - 1; - desired_tm.tm_mday = 31; - desired_tm.tm_year = 2018 - 1900; - desired_tm.tm_hour = 10; - desired_tm.tm_min = 35; - desired_tm.tm_sec = 23; - - false_now = mktime(&desired_tm); - - struct timeval now = { .tv_sec = false_now }; - settimeofday(&now, NULL); - } - test_spiffs_create_file_with_text(filename, ""); - - // 00:00:00. January 1st, 1900 - desired_tm.tm_mon = 1 - 1; - desired_tm.tm_mday = 1; - desired_tm.tm_year = 0; - desired_tm.tm_hour = 0; - desired_tm.tm_min = 0; - desired_tm.tm_sec = 0; - printf("Testing mod. time: %s", asctime(&desired_tm)); - desired_time.modtime = mktime(&desired_tm); - TEST_ASSERT_EQUAL(0, utime(filename, &desired_time)); - TEST_ASSERT_EQUAL(0, stat(filename, &achieved_stat)); - TEST_ASSERT_EQUAL_UINT32(desired_time.modtime, achieved_stat.st_mtime); - - // 23:59:08. December 31st, 2145 - desired_tm.tm_mon = 12 - 1; - desired_tm.tm_mday = 31; - desired_tm.tm_year = 2145 - 1900; - desired_tm.tm_hour = 23; - desired_tm.tm_min = 59; - desired_tm.tm_sec = 8; - printf("Testing mod. time: %s", asctime(&desired_tm)); - desired_time.modtime = mktime(&desired_tm); - TEST_ASSERT_EQUAL(0, utime(filename, &desired_time)); - TEST_ASSERT_EQUAL(0, stat(filename, &achieved_stat)); - TEST_ASSERT_EQUAL_UINT32(desired_time.modtime, achieved_stat.st_mtime); - - // Current time - TEST_ASSERT_EQUAL(0, utime(filename, NULL)); - TEST_ASSERT_EQUAL(0, stat(filename, &achieved_stat)); - printf("Mod. time changed to (false actual time): %s", ctime(&achieved_stat.st_mtime)); - TEST_ASSERT_NOT_EQUAL(desired_time.modtime, achieved_stat.st_mtime); - TEST_ASSERT(false_now - achieved_stat.st_mtime <= 2); // two seconds of tolerance are given - - test_teardown(); -} -#endif // CONFIG_SPIFFS_USE_MTIME - -static void test_spiffs_rw_speed(const char* filename, void* buf, size_t buf_size, size_t file_size, bool is_write) -{ - const size_t buf_count = file_size / buf_size; - - FILE* f = fopen(filename, (is_write) ? "wb" : "rb"); - TEST_ASSERT_NOT_NULL(f); - - struct timeval tv_start; - gettimeofday(&tv_start, NULL); - for (size_t n = 0; n < buf_count; ++n) { - if (is_write) { - TEST_ASSERT_EQUAL(buf_size, write(fileno(f), buf, buf_size)); - } else { - if (read(fileno(f), buf, buf_size) != buf_size) { - printf("reading at n=%d, eof=%d", n, feof(f)); - TEST_FAIL(); - } - } - } - - struct timeval tv_end; - gettimeofday(&tv_end, NULL); - - TEST_ASSERT_EQUAL(0, fclose(f)); - - float t_s = tv_end.tv_sec - tv_start.tv_sec + 1e-6f * (tv_end.tv_usec - tv_start.tv_usec); - printf("%s %d bytes (block size %d) in %.3fms (%.3f MB/s)\n", - (is_write)?"Wrote":"Read", file_size, buf_size, t_s * 1e3, - file_size / (1024.0f * 1024.0f * t_s)); -} - -TEST_CASE("write/read speed test", "[spiffs][timeout=60]") -{ - /* Erase partition before running the test to get consistent results */ - const esp_partition_t* part = get_partition(); - esp_partition_erase_range(part, 0, part->size); - - test_setup(); - - const size_t buf_size = 16 * 1024; - uint32_t* buf = (uint32_t*) calloc(1, buf_size); - esp_fill_random(buf, buf_size); - const size_t file_size = part->size / 2; - const char* file = "/spiffs/speedtest.bin"; - - test_spiffs_rw_speed(file, buf, 4 * 1024, file_size, true); - TEST_ASSERT_EQUAL(0, unlink(file)); - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, file_size)); - - test_spiffs_rw_speed(file, buf, 8 * 1024, file_size, true); - TEST_ASSERT_EQUAL(0, unlink(file)); - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, file_size)); - - test_spiffs_rw_speed(file, buf, 16 * 1024, file_size, true); - - test_spiffs_rw_speed(file, buf, 4 * 1024, file_size, false); - test_spiffs_rw_speed(file, buf, 8 * 1024, file_size, false); - test_spiffs_rw_speed(file, buf, 16 * 1024, file_size, false); - TEST_ASSERT_EQUAL(0, unlink(file)); - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, file_size)); - - free(buf); - test_teardown(); -} - -TEST_CASE("SPIFFS garbage-collect", "[spiffs][timeout=60]") -{ - // should fail until the partition is initialized - TEST_ESP_ERR(ESP_ERR_INVALID_STATE, esp_spiffs_gc(spiffs_test_partition_label, 4096)); - - test_setup(); - - // reclaiming one block should be possible - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, 4096)); - - // shouldn't be possible to reclaim more than the partition size - const esp_partition_t* part = get_partition(); - TEST_ESP_ERR(ESP_ERR_NOT_FINISHED, esp_spiffs_gc(spiffs_test_partition_label, part->size * 2)); - - test_teardown(); -} diff --git a/components/spiffs/test_apps/partitions.csv b/components/spiffs/test_apps/partitions.csv deleted file mode 100644 index 8cbcb7ebc3bb..000000000000 --- a/components/spiffs/test_apps/partitions.csv +++ /dev/null @@ -1,3 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -factory, 0, 0, 0x10000, 1M -storage, data, spiffs, , 256k diff --git a/components/spiffs/test_apps/pytest_spiffs.py b/components/spiffs/test_apps/pytest_spiffs.py deleted file mode 100644 index 33e5253937a8..000000000000 --- a/components/spiffs/test_apps/pytest_spiffs.py +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: CC0-1.0 - -import pytest -from pytest_embedded import Dut - - -@pytest.mark.esp32 -@pytest.mark.esp32c3 -@pytest.mark.generic -@pytest.mark.parametrize('config', [ - 'default', - 'release', -], indirect=True) -def test_spiffs_generic(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output(timeout=120) - - -@pytest.mark.esp32s3 -@pytest.mark.quad_psram -@pytest.mark.parametrize('config', [ - 'psram', -], indirect=True) -def test_spiffs_psram(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output(timeout=120) diff --git a/components/spiffs/test_apps/sdkconfig.ci.default b/components/spiffs/test_apps/sdkconfig.ci.default deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/components/spiffs/test_apps/sdkconfig.ci.psram.esp32s3 b/components/spiffs/test_apps/sdkconfig.ci.psram.esp32s3 deleted file mode 100644 index e8fd8d2ae308..000000000000 --- a/components/spiffs/test_apps/sdkconfig.ci.psram.esp32s3 +++ /dev/null @@ -1,3 +0,0 @@ -CONFIG_IDF_TARGET="esp32s3" -CONFIG_SPIRAM=y -CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0 diff --git a/components/spiffs/test_apps/sdkconfig.ci.release b/components/spiffs/test_apps/sdkconfig.ci.release deleted file mode 100644 index 4983b4dfe379..000000000000 --- a/components/spiffs/test_apps/sdkconfig.ci.release +++ /dev/null @@ -1 +0,0 @@ -CONFIG_COMPILER_OPTIMIZATION_SIZE=y diff --git a/components/spiffs/test_apps/sdkconfig.defaults b/components/spiffs/test_apps/sdkconfig.defaults deleted file mode 100644 index b3a25e0021c7..000000000000 --- a/components/spiffs/test_apps/sdkconfig.defaults +++ /dev/null @@ -1,21 +0,0 @@ -# General options for additional checks -CONFIG_HEAP_POISONING_COMPREHENSIVE=y -CONFIG_COMPILER_WARN_WRITE_STRINGS=y -CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y -CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y -CONFIG_COMPILER_STACK_CHECK=y - -# Disable the task watchdog since this app uses an interactive menu -CONFIG_ESP_TASK_WDT_INIT=n - -# Custom partition table for this test app -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" - -# SPIFFS-specific settings -CONFIG_SPIFFS_USE_MTIME=y - -# Set sufficient number of GC runs for SPIFFS: -# size of the storage partition divided by flash sector size. -# See esp_spiffs_gc description for more info. -CONFIG_SPIFFS_GC_MAX_RUNS=64 diff --git a/components/spiffs/test_spiffsgen/__init__.py b/components/spiffs/test_spiffsgen/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/components/spiffs/test_spiffsgen/test_spiffsgen.py b/components/spiffs/test_spiffsgen/test_spiffsgen.py deleted file mode 100755 index 44f9d2851c35..000000000000 --- a/components/spiffs/test_spiffsgen/test_spiffsgen.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Apache-2.0 -import os -import sys -import unittest - -try: - import typing -except ImportError: - pass - -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) -try: - import spiffsgen -except ImportError: - raise - - -class SpiffsgenTest(unittest.TestCase): - def test_configs(self): # type: () -> None - """Run spiffsgen with different configs, and check that - an image is generated (there is no exception), and the image size - is as expected. - """ - default_config = dict( - page_size=256, - page_ix_len=spiffsgen.SPIFFS_PAGE_IX_LEN, - block_size=4096, - block_ix_len=spiffsgen.SPIFFS_BLOCK_IX_LEN, - meta_len=4, - obj_name_len=32, - obj_id_len=spiffsgen.SPIFFS_BLOCK_IX_LEN, - span_ix_len=spiffsgen.SPIFFS_SPAN_IX_LEN, - packed=True, - aligned=True, - endianness='little', - use_magic=True, - use_magic_len=True, - aligned_obj_ix_tables=False - ) - - def make_config(**kwargs): # type: (typing.Any) -> spiffsgen.SpiffsBuildConfig - """Return SpiffsBuildConfig object with configuration set - by default_config plus any options overridden in kwargs. - """ - new_config = dict(default_config) - new_config.update(**kwargs) - return spiffsgen.SpiffsBuildConfig(**new_config) - - configs = [ - make_config(), - make_config(use_magic_len=False, use_magic=False, aligned_obj_ix_tables=True), - make_config(meta_len=4, obj_name_len=16), - make_config(block_size=8192), - make_config(page_size=512) - ] - - image_size = 64 * 1024 - for config in configs: - spiffs = spiffsgen.SpiffsFS(image_size, config) - spiffs.create_file('/test', __file__) - image = spiffs.to_binary() - self.assertEqual(len(image), image_size) - # Note: it would be nice to compile spiffs for host with the given - # config, and verify that the image is parsed correctly. - - -if __name__ == '__main__': - unittest.main() diff --git a/components/wifi_provisioning/CMakeLists.txt b/components/wifi_provisioning/CMakeLists.txt deleted file mode 100644 index 96cfdd5665a7..000000000000 --- a/components/wifi_provisioning/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -idf_build_get_property(target IDF_TARGET) - -if(${target} STREQUAL "linux") - return() # This component is not supported by the POSIX/Linux simulator -endif() - -set(srcs "src/wifi_config.c" - "src/wifi_scan.c" - "src/wifi_ctrl.c" - "src/manager.c" - "src/handlers.c" - "src/scheme_console.c" - "proto-c/wifi_config.pb-c.c" - "proto-c/wifi_scan.pb-c.c" - "proto-c/wifi_ctrl.pb-c.c" - "proto-c/wifi_constants.pb-c.c") - -if(CONFIG_ESP_WIFI_SOFTAP_SUPPORT) - list(APPEND srcs "src/scheme_softap.c") -endif() - -if(CONFIG_BT_ENABLED) - if(CONFIG_BT_BLUEDROID_ENABLED OR CONFIG_BT_NIMBLE_ENABLED) - list(APPEND srcs - "src/scheme_ble.c") - endif() -endif() - -idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS include - PRIV_INCLUDE_DIRS src proto-c - REQUIRES lwip protocomm - PRIV_REQUIRES protobuf-c bt json esp_timer esp_wifi) diff --git a/components/wifi_provisioning/Kconfig b/components/wifi_provisioning/Kconfig deleted file mode 100644 index 9403d0ee2303..000000000000 --- a/components/wifi_provisioning/Kconfig +++ /dev/null @@ -1,62 +0,0 @@ -menu "Wi-Fi Provisioning Manager" - - config WIFI_PROV_SCAN_MAX_ENTRIES - int "Max Wi-Fi Scan Result Entries" - default 16 - range 1 255 - help - This sets the maximum number of entries of Wi-Fi scan results that will be kept by the provisioning manager - - config WIFI_PROV_AUTOSTOP_TIMEOUT - int "Provisioning auto-stop timeout" - default 30 - range 5 600 - help - Time (in seconds) after which the Wi-Fi provisioning manager will auto-stop after connecting to - a Wi-Fi network successfully. - - config WIFI_PROV_BLE_BONDING - bool - prompt "Enable BLE bonding" - depends on BT_ENABLED - help - This option is applicable only when provisioning transport is BLE. - - config WIFI_PROV_BLE_SEC_CONN - bool - prompt "Enable BLE Secure connection flag" - depends on BT_NIMBLE_ENABLED - default y - help - Used to enable Secure connection support when provisioning transport is BLE. - - config WIFI_PROV_BLE_FORCE_ENCRYPTION - bool - prompt "Force Link Encryption during characteristic Read / Write" - help - Used to enforce link encryption when attempting to read / write characteristic - - config WIFI_PROV_KEEP_BLE_ON_AFTER_PROV - bool "Keep BT on after provisioning is done" - depends on BT_ENABLED - select ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP - - config WIFI_PROV_DISCONNECT_AFTER_PROV - bool "Terminate connection after provisioning is done" - depends on WIFI_PROV_KEEP_BLE_ON_AFTER_PROV - default y - select ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP - - choice WIFI_PROV_STA_SCAN_METHOD - bool "Wifi Provisioning Scan Method" - default WIFI_PROV_STA_ALL_CHANNEL_SCAN - config WIFI_PROV_STA_ALL_CHANNEL_SCAN - bool "All Channel Scan" - help - Scan will end after scanning the entire channel. This option is useful in Mesh WiFi Systems. - config WIFI_PROV_STA_FAST_SCAN - bool "Fast Scan" - help - Scan will end after an AP matching with the SSID has been detected. - endchoice -endmenu diff --git a/components/wifi_provisioning/include/wifi_provisioning/manager.h b/components/wifi_provisioning/include/wifi_provisioning/manager.h deleted file mode 100644 index b8780762f616..000000000000 --- a/components/wifi_provisioning/include/wifi_provisioning/manager.h +++ /dev/null @@ -1,608 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "esp_event.h" -#include "esp_wifi_types.h" -#include "wifi_provisioning/wifi_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ESP_EVENT_DECLARE_BASE(WIFI_PROV_EVENT); - -/** - * @brief Events generated by manager - * - * These events are generated in order of declaration and, for the - * stretch of time between initialization and de-initialization of - * the manager, each event is signaled only once - */ -typedef enum { - /** - * Emitted when the manager is initialized - */ - WIFI_PROV_INIT, - - /** - * Indicates that provisioning has started - */ - WIFI_PROV_START, - - /** - * Emitted when Wi-Fi AP credentials are received via `protocomm` - * endpoint `wifi_config`. The event data in this case is a pointer - * to the corresponding `wifi_sta_config_t` structure - */ - WIFI_PROV_CRED_RECV, - - /** - * Emitted when device fails to connect to the AP of which the - * credentials were received earlier on event `WIFI_PROV_CRED_RECV`. - * The event data in this case is a pointer to the disconnection - * reason code with type `wifi_prov_sta_fail_reason_t` - */ - WIFI_PROV_CRED_FAIL, - - /** - * Emitted when device successfully connects to the AP of which the - * credentials were received earlier on event `WIFI_PROV_CRED_RECV` - */ - WIFI_PROV_CRED_SUCCESS, - - /** - * Signals that provisioning service has stopped - */ - WIFI_PROV_END, - - /** - * Signals that manager has been de-initialized - */ - WIFI_PROV_DEINIT, -} wifi_prov_cb_event_t; - -typedef void (*wifi_prov_cb_func_t)(void *user_data, wifi_prov_cb_event_t event, void *event_data); - -/** - * @brief Event handler that is used by the manager while - * provisioning service is active - */ -typedef struct { - /** - * Callback function to be executed on provisioning events - */ - wifi_prov_cb_func_t event_cb; - - /** - * User context data to pass as parameter to callback function - */ - void *user_data; -} wifi_prov_event_handler_t; - -/** - * @brief Event handler can be set to none if not used - */ -#define WIFI_PROV_EVENT_HANDLER_NONE { \ - .event_cb = NULL, \ - .user_data = NULL \ -} - -/** - * @brief Structure for specifying the provisioning scheme to be - * followed by the manager - * - * @note Ready to use schemes are available: - * - wifi_prov_scheme_ble : for provisioning over BLE transport + GATT server - * - wifi_prov_scheme_softap : for provisioning over SoftAP transport + HTTP server - * - wifi_prov_scheme_console : for provisioning over Serial UART transport + Console (for debugging) - */ -typedef struct wifi_prov_scheme { - /** - * Function which is to be called by the manager when it is to - * start the provisioning service associated with a protocomm instance - * and a scheme specific configuration - */ - esp_err_t (*prov_start) (protocomm_t *pc, void *config); - - /** - * Function which is to be called by the manager to stop the - * provisioning service previously associated with a protocomm instance - */ - esp_err_t (*prov_stop) (protocomm_t *pc); - - /** - * Function which is to be called by the manager to generate - * a new configuration for the provisioning service, that is - * to be passed to prov_start() - */ - void *(*new_config) (void); - - /** - * Function which is to be called by the manager to delete a - * configuration generated using new_config() - */ - void (*delete_config) (void *config); - - /** - * Function which is to be called by the manager to set the - * service name and key values in the configuration structure - */ - esp_err_t (*set_config_service) (void *config, const char *service_name, const char *service_key); - - /** - * Function which is to be called by the manager to set a protocomm endpoint - * with an identifying name and UUID in the configuration structure - */ - esp_err_t (*set_config_endpoint) (void *config, const char *endpoint_name, uint16_t uuid); - - /** - * Sets mode of operation of Wi-Fi during provisioning - * This is set to : - * - WIFI_MODE_APSTA for SoftAP transport - * - WIFI_MODE_STA for BLE transport - */ - wifi_mode_t wifi_mode; -} wifi_prov_scheme_t; - -/** - * @brief Structure for specifying the manager configuration - */ -typedef struct { - /** - * Provisioning scheme to use. Following schemes are already available: - * - wifi_prov_scheme_ble : for provisioning over BLE transport + GATT server - * - wifi_prov_scheme_softap : for provisioning over SoftAP transport + HTTP server + mDNS (optional) - * - wifi_prov_scheme_console : for provisioning over Serial UART transport + Console (for debugging) - */ - wifi_prov_scheme_t scheme; - - /** - * Event handler required by the scheme for incorporating scheme specific - * behavior while provisioning manager is running. Various options may be - * provided by the scheme for setting this field. Use WIFI_PROV_EVENT_HANDLER_NONE - * when not used. When using scheme wifi_prov_scheme_ble, the following - * options are available: - * - WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM - * - WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BLE - * - WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BT - */ - wifi_prov_event_handler_t scheme_event_handler; - - /** - * Event handler that can be set for the purpose of incorporating application - * specific behavior. Use WIFI_PROV_EVENT_HANDLER_NONE when not used. - */ - wifi_prov_event_handler_t app_event_handler; -} wifi_prov_mgr_config_t; - -/** - * @brief Security modes supported by the Provisioning Manager. - * - * These are same as the security modes provided by protocomm - */ -typedef enum wifi_prov_security { -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_0 - /** - * No security (plain-text communication) - */ - WIFI_PROV_SECURITY_0 = 0, -#endif -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1 - /** - * This secure communication mode consists of - * X25519 key exchange - * + proof of possession (pop) based authentication - * + AES-CTR encryption - */ - WIFI_PROV_SECURITY_1 = 1, -#endif -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2 - /** - * This secure communication mode consists of - * SRP6a based authentication and key exchange - * + AES-GCM encryption/decryption - */ - WIFI_PROV_SECURITY_2 = 2 -#endif -} wifi_prov_security_t; - -/** - * @brief Security 1 params structure - * This needs to be passed when using WIFI_PROV_SECURITY_1 - */ -typedef const char wifi_prov_security1_params_t; - -/** - * @brief Security 2 params structure - * This needs to be passed when using WIFI_PROV_SECURITY_2 - */ -typedef protocomm_security2_params_t wifi_prov_security2_params_t; - -/** - * @brief Initialize provisioning manager instance - * - * Configures the manager and allocates internal resources - * - * Configuration specifies the provisioning scheme (transport) - * and event handlers - * - * Event WIFI_PROV_INIT is emitted right after initialization - * is complete - * - * @param[in] config Configuration structure - * - * @return - * - ESP_OK : Success - * - ESP_FAIL : Fail - */ -esp_err_t wifi_prov_mgr_init(wifi_prov_mgr_config_t config); - -/** - * @brief Stop provisioning (if running) and release - * resource used by the manager - * - * Event WIFI_PROV_DEINIT is emitted right after de-initialization - * is finished - * - * If provisioning service is still active when this API is called, - * it first stops the service, hence emitting WIFI_PROV_END, and - * then performs the de-initialization - */ -void wifi_prov_mgr_deinit(void); - -/** - * @brief Checks if device is provisioned - * - * This checks if Wi-Fi credentials are present on the NVS - * - * The Wi-Fi credentials are assumed to be kept in the same - * NVS namespace as used by esp_wifi component - * - * If one were to call esp_wifi_set_config() directly instead - * of going through the provisioning process, this function will - * still yield true (i.e. device will be found to be provisioned) - * - * @note Calling wifi_prov_mgr_start_provisioning() automatically - * resets the provision state, irrespective of what the - * state was prior to making the call. - * - * @param[out] provisioned True if provisioned, else false - * - * @return - * - ESP_OK : Retrieved provision state successfully - * - ESP_FAIL : Wi-Fi not initialized - * - ESP_ERR_INVALID_ARG : Null argument supplied - */ -esp_err_t wifi_prov_mgr_is_provisioned(bool *provisioned); - -/** - * @brief Checks whether the provisioning state machine is idle - * - * @return True if state machine is idle, else false - */ -bool wifi_prov_mgr_is_sm_idle(void); - -/** - * @brief Start provisioning service - * - * This starts the provisioning service according to the scheme - * configured at the time of initialization. For scheme : - * - wifi_prov_scheme_ble : This starts protocomm_ble, which internally initializes - * BLE transport and starts GATT server for handling - * provisioning requests - * - wifi_prov_scheme_softap : This activates SoftAP mode of Wi-Fi and starts - * protocomm_httpd, which internally starts an HTTP - * server for handling provisioning requests (If mDNS is - * active it also starts advertising service with type - * _esp_wifi_prov._tcp) - * - * Event WIFI_PROV_START is emitted right after provisioning starts without failure - * - * @note This API will start provisioning service even if device is found to be - * already provisioned, i.e. wifi_prov_mgr_is_provisioned() yields true - * - * @param[in] security Specify which protocomm security scheme to use : - * - WIFI_PROV_SECURITY_0 : For no security - * - WIFI_PROV_SECURITY_1 : x25519 secure handshake for session - * establishment followed by AES-CTR encryption of provisioning messages - * - WIFI_PROV_SECURITY_2: SRP6a based authentication and key exchange - * followed by AES-GCM encryption/decryption of provisioning messages - * @param[in] wifi_prov_sec_params - * Pointer to security params (NULL if not needed). - * This is not needed for protocomm security 0 - * This pointer should hold the struct of type - * wifi_prov_security1_params_t for protocomm security 1 - * and wifi_prov_security2_params_t for protocomm security 2 respectively. - * This pointer and its contents should be valid till the provisioning service is - * running and has not been stopped or de-inited. - * @param[in] service_name Unique name of the service. This translates to: - * - Wi-Fi SSID when provisioning mode is softAP - * - Device name when provisioning mode is BLE - * @param[in] service_key Key required by client to access the service (NULL if not needed). - * This translates to: - * - Wi-Fi password when provisioning mode is softAP - * - ignored when provisioning mode is BLE - * - * @return - * - ESP_OK : Provisioning started successfully - * - ESP_FAIL : Failed to start provisioning service - * - ESP_ERR_INVALID_STATE : Provisioning manager not initialized or already started - */ -esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const void *wifi_prov_sec_params, const char *service_name, const char *service_key); - -/** - * @brief Stop provisioning service - * - * If provisioning service is active, this API will initiate a process to stop - * the service and return. Once the service actually stops, the event WIFI_PROV_END - * will be emitted. - * - * If wifi_prov_mgr_deinit() is called without calling this API first, it will - * automatically stop the provisioning service and emit the WIFI_PROV_END, followed - * by WIFI_PROV_DEINIT, before returning. - * - * This API will generally be used along with wifi_prov_mgr_disable_auto_stop() - * in the scenario when the main application has registered its own endpoints, - * and wishes that the provisioning service is stopped only when some protocomm - * command from the client side application is received. - * - * Calling this API inside an endpoint handler, with sufficient cleanup_delay, - * will allow the response / acknowledgment to be sent successfully before the - * underlying protocomm service is stopped. - * - * Cleaup_delay is set when calling wifi_prov_mgr_disable_auto_stop(). - * If not specified, it defaults to 1000ms. - * - * For straightforward cases, using this API is usually not necessary as - * provisioning is stopped automatically once WIFI_PROV_CRED_SUCCESS is emitted. - * Stopping is delayed (maximum 30 seconds) thus allowing the client side - * application to query for Wi-Fi state, i.e. after receiving the first query - * and sending `Wi-Fi state connected` response the service is stopped immediately. - */ -void wifi_prov_mgr_stop_provisioning(void); - -/** - * @brief Wait for provisioning service to finish - * - * Calling this API will block until provisioning service is stopped - * i.e. till event WIFI_PROV_END is emitted. - * - * This will not block if provisioning is not started or not initialized. - */ -void wifi_prov_mgr_wait(void); - -/** - * @brief Disable auto stopping of provisioning service upon completion - * - * By default, once provisioning is complete, the provisioning service is automatically - * stopped, and all endpoints (along with those registered by main application) are - * deactivated. - * - * This API is useful in the case when main application wishes to close provisioning service - * only after it receives some protocomm command from the client side app. For example, after - * connecting to Wi-Fi, the device may want to connect to the cloud, and only once that is - * successfully, the device is said to be fully configured. But, then it is upto the main - * application to explicitly call wifi_prov_mgr_stop_provisioning() later when the device is - * fully configured and the provisioning service is no longer required. - * - * @note This must be called before executing wifi_prov_mgr_start_provisioning() - * - * @param[in] cleanup_delay Sets the delay after which the actual cleanup of transport related - * resources is done after a call to wifi_prov_mgr_stop_provisioning() - * returns. Minimum allowed value is 100ms. If not specified, this will - * default to 1000ms. - * - * @return - * - ESP_OK : Success - * - ESP_ERR_INVALID_STATE : Manager not initialized or - * provisioning service already started - */ -esp_err_t wifi_prov_mgr_disable_auto_stop(uint32_t cleanup_delay); - -/** - * @brief Set application version and capabilities in the JSON data returned by - * proto-ver endpoint - * - * This function can be called multiple times, to specify information about the various - * application specific services running on the device, identified by unique labels. - * - * The provisioning service itself registers an entry in the JSON data, by the label "prov", - * containing only provisioning service version and capabilities. Application services should - * use a label other than "prov" so as not to overwrite this. - * - * @note This must be called before executing wifi_prov_mgr_start_provisioning() - * - * @param[in] label String indicating the application name. - * - * @param[in] version String indicating the application version. - * There is no constraint on format. - * - * @param[in] capabilities Array of strings with capabilities. - * These could be used by the client side app to know - * the application registered endpoint capabilities - * - * @param[in] total_capabilities Size of capabilities array - * - * @return - * - ESP_OK : Success - * - ESP_ERR_INVALID_STATE : Manager not initialized or - * provisioning service already started - * - ESP_ERR_NO_MEM : Failed to allocate memory for version string - * - ESP_ERR_INVALID_ARG : Null argument - */ -esp_err_t wifi_prov_mgr_set_app_info(const char *label, const char *version, - const char**capabilities, size_t total_capabilities); - -/** - * @brief Create an additional endpoint and allocate internal resources for it - * - * This API is to be called by the application if it wants to create an additional - * endpoint. All additional endpoints will be assigned UUIDs starting from 0xFF54 - * and so on in the order of execution. - * - * protocomm handler for the created endpoint is to be registered later using - * wifi_prov_mgr_endpoint_register() after provisioning has started. - * - * @note This API can only be called BEFORE provisioning is started - * - * @note Additional endpoints can be used for configuring client provided - * parameters other than Wi-Fi credentials, that are necessary for the - * main application and hence must be set prior to starting the application - * - * @note After session establishment, the additional endpoints must be targeted - * first by the client side application before sending Wi-Fi configuration, - * because once Wi-Fi configuration finishes the provisioning service is - * stopped and hence all endpoints are unregistered - * - * @param[in] ep_name unique name of the endpoint - * - * @return - * - ESP_OK : Success - * - ESP_FAIL : Failure - */ -esp_err_t wifi_prov_mgr_endpoint_create(const char *ep_name); - -/** - * @brief Register a handler for the previously created endpoint - * - * This API can be called by the application to register a protocomm handler - * to any endpoint that was created using wifi_prov_mgr_endpoint_create(). - * - * @note This API can only be called AFTER provisioning has started - * - * @note Additional endpoints can be used for configuring client provided - * parameters other than Wi-Fi credentials, that are necessary for the - * main application and hence must be set prior to starting the application - * - * @note After session establishment, the additional endpoints must be targeted - * first by the client side application before sending Wi-Fi configuration, - * because once Wi-Fi configuration finishes the provisioning service is - * stopped and hence all endpoints are unregistered - * - * @param[in] ep_name Name of the endpoint - * @param[in] handler Endpoint handler function - * @param[in] user_ctx User data - * - * @return - * - ESP_OK : Success - * - ESP_FAIL : Failure - */ -esp_err_t wifi_prov_mgr_endpoint_register(const char *ep_name, - protocomm_req_handler_t handler, - void *user_ctx); - -/** - * @brief Unregister the handler for an endpoint - * - * This API can be called if the application wants to selectively - * unregister the handler of an endpoint while the provisioning - * is still in progress. - * - * All the endpoint handlers are unregistered automatically when - * the provisioning stops. - * - * @param[in] ep_name Name of the endpoint - */ -void wifi_prov_mgr_endpoint_unregister(const char *ep_name); - -/** - * @brief Get state of Wi-Fi Station during provisioning - * - * @param[out] state Pointer to wifi_prov_sta_state_t - * variable to be filled - * - * @return - * - ESP_OK : Successfully retrieved Wi-Fi state - * - ESP_FAIL : Provisioning app not running - */ -esp_err_t wifi_prov_mgr_get_wifi_state(wifi_prov_sta_state_t *state); - -/** - * @brief Get reason code in case of Wi-Fi station - * disconnection during provisioning - * -* @param[out] reason Pointer to wifi_prov_sta_fail_reason_t -* variable to be filled - * - * @return - * - ESP_OK : Successfully retrieved Wi-Fi disconnect reason - * - ESP_FAIL : Provisioning app not running - */ -esp_err_t wifi_prov_mgr_get_wifi_disconnect_reason(wifi_prov_sta_fail_reason_t *reason); - -/** - * @brief Runs Wi-Fi as Station with the supplied configuration - * - * Configures the Wi-Fi station mode to connect to the AP with - * SSID and password specified in config structure and sets - * Wi-Fi to run as station. - * - * This is automatically called by provisioning service upon - * receiving new credentials. - * - * If credentials are to be supplied to the manager via a - * different mode other than through protocomm, then this - * API needs to be called. - * - * Event WIFI_PROV_CRED_RECV is emitted after credentials have - * been applied and Wi-Fi station started - * - * @param[in] wifi_cfg Pointer to Wi-Fi configuration structure - * - * @return - * - ESP_OK : Wi-Fi configured and started successfully - * - ESP_FAIL : Failed to set configuration - */ -esp_err_t wifi_prov_mgr_configure_sta(wifi_config_t *wifi_cfg); - -/** - * @brief Reset Wi-Fi provisioning config - * - * Calling this API will restore WiFi stack persistent settings to default values. - * - * @return - * - ESP_OK : Reset provisioning config successfully - * - ESP_FAIL : Failed to reset provisioning config - */ -esp_err_t wifi_prov_mgr_reset_provisioning(void); - -/** - * @brief Reset internal state machine and clear provisioned credentials. - * - * This API should be used to restart provisioning ONLY in the case - * of provisioning failures without rebooting the device. - * - * @return - * - ESP_OK : Reset provisioning state machine successfully - * - ESP_FAIL : Failed to reset provisioning state machine - * - ESP_ERR_INVALID_STATE : Manager not initialized - */ -esp_err_t wifi_prov_mgr_reset_sm_state_on_failure(void); - -/** - * @brief Reset internal state machine and clear provisioned credentials. - * - * This API can be used to restart provisioning ONLY in case the device is - * to be provisioned again for new credentials after a previous successful - * provisioning without rebooting the device. - * - * @note This API can be used only if provisioning auto-stop has been - * disabled using wifi_prov_mgr_disable_auto_stop() - * - * @return - * - ESP_OK : Reset provisioning state machine successfully - * - ESP_FAIL : Failed to reset provisioning state machine - * - ESP_ERR_INVALID_STATE : Manager not initialized - */ -esp_err_t wifi_prov_mgr_reset_sm_state_for_reprovision(void); - -#ifdef __cplusplus -} -#endif diff --git a/components/wifi_provisioning/include/wifi_provisioning/scheme_ble.h b/components/wifi_provisioning/include/wifi_provisioning/scheme_ble.h deleted file mode 100644 index c30a3a86b8b7..000000000000 --- a/components/wifi_provisioning/include/wifi_provisioning/scheme_ble.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include - -#include "wifi_provisioning/manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Scheme that can be used by manager for provisioning - * over BLE transport with GATT server - */ -extern const wifi_prov_scheme_t wifi_prov_scheme_ble; - -/* This scheme specific event handler is to be used when application - * doesn't require BT and BLE after provisioning has finished */ -#define WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM { \ - .event_cb = wifi_prov_scheme_ble_event_cb_free_btdm, \ - .user_data = NULL \ -} - -/* This scheme specific event handler is to be used when application - * doesn't require BLE to be active after provisioning has finished */ -#define WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BLE { \ - .event_cb = wifi_prov_scheme_ble_event_cb_free_ble, \ - .user_data = NULL \ -} - -/* This scheme specific event handler is to be used when application - * doesn't require BT to be active after provisioning has finished */ -#define WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BT { \ - .event_cb = wifi_prov_scheme_ble_event_cb_free_bt, \ - .user_data = NULL \ -} - -void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event_t event, void *event_data); -void wifi_prov_scheme_ble_event_cb_free_ble (void *user_data, wifi_prov_cb_event_t event, void *event_data); -void wifi_prov_scheme_ble_event_cb_free_bt (void *user_data, wifi_prov_cb_event_t event, void *event_data); - -/** - * @brief Set the 128 bit GATT service UUID used for provisioning - * - * This API is used to override the default 128 bit provisioning - * service UUID, which is 0000ffff-0000-1000-8000-00805f9b34fb. - * - * This must be called before starting provisioning, i.e. before - * making a call to wifi_prov_mgr_start_provisioning(), otherwise - * the default UUID will be used. - * - * @note The data being pointed to by the argument must be valid - * at least till provisioning is started. Upon start, the - * manager will store an internal copy of this UUID, and - * this data can be freed or invalidated afterwards. - * - * @param[in] uuid128 A custom 128 bit UUID - * - * @return - * - ESP_OK : Success - * - ESP_ERR_INVALID_ARG : Null argument - */ -esp_err_t wifi_prov_scheme_ble_set_service_uuid(uint8_t *uuid128); - -/** - * @brief Set manufacturer specific data in scan response - * - * This must be called before starting provisioning, i.e. before - * making a call to wifi_prov_mgr_start_provisioning(). - * - * @note It is important to understand that length of custom manufacturer - * data should be within limits. The manufacturer data goes into scan - * response along with BLE device name. By default, BLE device name - * length is of 11 Bytes, however it can vary as per application use - * case. So, one has to honour the scan response data size limits i.e. - * (mfg_data_len + 2) < 31 - (device_name_length + 2 ). If the - * mfg_data length exceeds this limit, the length will be truncated. - * - * @param[in] mfg_data Custom manufacturer data - * @param[in] mfg_data_len Manufacturer data length - * - * @return - * - ESP_OK : Success - * - ESP_ERR_INVALID_ARG : Null argument - */ -esp_err_t wifi_prov_scheme_ble_set_mfg_data(uint8_t *mfg_data, ssize_t mfg_data_len); - -/** - * @brief Set Bluetooth Random address - * - * This must be called before starting provisioning, i.e. before - * making a call to wifi_prov_mgr_start_provisioning(). - * - * This API can be used in cases where a new identity address is to be used during - * provisioning. This will result in this device being treated as a new device by remote - * devices. - * - * @note This API will change the existing BD address for the device. The address once - * set will remain unchanged until BLE stack tear down happens when - * wifi_prov_mgr_deinit is invoked. - * - * This API is only to be called to set random address. Re-invoking this API - * after provisioning is started will have no effect. - * - * @param[in] rand_addr The static random address to be set of length 6 bytes. - * - * @return - * - ESP_OK : Success - * - ESP_ERR_INVALID_ARG : Null argument - */ -esp_err_t wifi_prov_scheme_ble_set_random_addr(const uint8_t *rand_addr); - -#ifdef __cplusplus -} -#endif diff --git a/components/wifi_provisioning/include/wifi_provisioning/scheme_console.h b/components/wifi_provisioning/include/wifi_provisioning/scheme_console.h deleted file mode 100644 index 760fe3243a59..000000000000 --- a/components/wifi_provisioning/include/wifi_provisioning/scheme_console.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include - -#include "wifi_provisioning/manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Scheme that can be used by manager for provisioning - * over console (Serial UART) - */ -extern const wifi_prov_scheme_t wifi_prov_scheme_console; - -#ifdef __cplusplus -} -#endif diff --git a/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h b/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h deleted file mode 100644 index eda48be0f7e9..000000000000 --- a/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include - -#include "wifi_provisioning/manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Scheme that can be used by manager for provisioning - * over SoftAP transport with HTTP server - */ -extern const wifi_prov_scheme_t wifi_prov_scheme_softap; - -/** - * - * @brief Provide HTTPD Server handle externally. - * - * Useful in cases wherein applications need the webserver for some - * different operations, and do not want the wifi provisioning component - * to start/stop a new instance. - * - * @note This API should be called before wifi_prov_mgr_start_provisioning() - * - * @param[in] handle Handle to HTTPD server instance - */ -void wifi_prov_scheme_softap_set_httpd_handle(void *handle); -#ifdef __cplusplus -} -#endif diff --git a/components/wifi_provisioning/include/wifi_provisioning/wifi_config.h b/components/wifi_provisioning/include/wifi_provisioning/wifi_config.h deleted file mode 100644 index 6c9d11f5ab1d..000000000000 --- a/components/wifi_provisioning/include/wifi_provisioning/wifi_config.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _WIFI_PROV_CONFIG_H_ -#define _WIFI_PROV_CONFIG_H_ - -#include "esp_netif_ip_addr.h" -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief WiFi STA status for conveying back to the provisioning master - */ -typedef enum { - WIFI_PROV_STA_CONNECTING, - WIFI_PROV_STA_CONNECTED, - WIFI_PROV_STA_DISCONNECTED -} wifi_prov_sta_state_t; - -/** - * @brief WiFi STA connection fail reason - */ -typedef enum { - WIFI_PROV_STA_AUTH_ERROR, - WIFI_PROV_STA_AP_NOT_FOUND -} wifi_prov_sta_fail_reason_t; - -/** - * @brief WiFi STA connected status information - */ -typedef struct { - /** - * IP Address received by station - */ - char ip_addr[IP4ADDR_STRLEN_MAX]; - - char bssid[6]; /*!< BSSID of the AP to which connection was estalished */ - char ssid[33]; /*!< SSID of the to which connection was estalished */ - uint8_t channel; /*!< Channel of the AP */ - uint8_t auth_mode; /*!< Authorization mode of the AP */ -} wifi_prov_sta_conn_info_t; - -/** - * @brief WiFi status data to be sent in response to `get_status` request from master - */ -typedef struct { - wifi_prov_sta_state_t wifi_state; /*!< WiFi state of the station */ - union { - /** - * Reason for disconnection (valid only when `wifi_state` is `WIFI_STATION_DISCONNECTED`) - */ - wifi_prov_sta_fail_reason_t fail_reason; - - /** - * Connection information (valid only when `wifi_state` is `WIFI_STATION_CONNECTED`) - */ - wifi_prov_sta_conn_info_t conn_info; - }; -} wifi_prov_config_get_data_t; - -/** - * @brief WiFi config data received by slave during `set_config` request from master - */ -typedef struct { - char ssid[33]; /*!< SSID of the AP to which the slave is to be connected */ - char password[64]; /*!< Password of the AP */ - char bssid[6]; /*!< BSSID of the AP */ - uint8_t channel; /*!< Channel of the AP */ -} wifi_prov_config_set_data_t; - -/** - * @brief Type of context data passed to each get/set/apply handler - * function set in `wifi_prov_config_handlers` structure. - * - * This is passed as an opaque pointer, thereby allowing it be defined - * later in application code as per requirements. - */ -typedef struct wifi_prov_ctx wifi_prov_ctx_t; - -/** - * @brief Internal handlers for receiving and responding to protocomm - * requests from master - * - * This is to be passed as priv_data for protocomm request handler - * (refer to `wifi_prov_config_data_handler()`) when calling `protocomm_add_endpoint()`. - */ -typedef struct wifi_prov_config_handlers { - /** - * Handler function called when connection status - * of the slave (in WiFi station mode) is requested - */ - esp_err_t (*get_status_handler)(wifi_prov_config_get_data_t *resp_data, - wifi_prov_ctx_t **ctx); - - /** - * Handler function called when WiFi connection configuration - * (eg. AP SSID, password, etc.) of the slave (in WiFi station mode) - * is to be set to user provided values - */ - esp_err_t (*set_config_handler)(const wifi_prov_config_set_data_t *req_data, - wifi_prov_ctx_t **ctx); - - /** - * Handler function for applying the configuration that was set in - * `set_config_handler`. After applying the station may get connected to - * the AP or may fail to connect. The slave must be ready to convey the - * updated connection status information when `get_status_handler` is - * invoked again by the master. - */ - esp_err_t (*apply_config_handler)(wifi_prov_ctx_t **ctx); - - /** - * Context pointer to be passed to above handler functions upon invocation - */ - wifi_prov_ctx_t *ctx; -} wifi_prov_config_handlers_t; - -/** - * @brief Handler for receiving and responding to requests from master - * - * This is to be registered as the `wifi_config` endpoint handler - * (protocomm `protocomm_req_handler_t`) using `protocomm_add_endpoint()` - */ -esp_err_t wifi_prov_config_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, - uint8_t **outbuf, ssize_t *outlen, void *priv_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/wifi_provisioning/include/wifi_provisioning/wifi_scan.h b/components/wifi_provisioning/include/wifi_provisioning/wifi_scan.h deleted file mode 100644 index a4ebb7e57002..000000000000 --- a/components/wifi_provisioning/include/wifi_provisioning/wifi_scan.h +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _PROV_WIFI_SCAN_H_ -#define _PROV_WIFI_SCAN_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define WIFI_SSID_LEN sizeof(((wifi_ap_record_t *)0)->ssid) -#define WIFI_BSSID_LEN sizeof(((wifi_ap_record_t *)0)->bssid) - -/** - * @brief Type of context data passed to each get/set/apply handler - * function set in `wifi_prov_scan_handlers` structure. - * - * This is passed as an opaque pointer, thereby allowing it be defined - * later in application code as per requirements. - */ -typedef struct wifi_prov_scan_ctx wifi_prov_scan_ctx_t; - -/** - * @brief Structure of entries in the scan results list - */ -typedef struct { - /** - * SSID of Wi-Fi AP - */ - char ssid[WIFI_SSID_LEN]; - - /** - * BSSID of Wi-Fi AP - */ - char bssid[WIFI_BSSID_LEN]; - - /** - * Wi-Fi channel number - */ - uint8_t channel; - - /** - * Signal strength - */ - int rssi; - - /** - * Wi-Fi security mode - */ - uint8_t auth; -} wifi_prov_scan_result_t; - -/** - * @brief Internal handlers for receiving and responding to protocomm - * requests from client - * - * This is to be passed as priv_data for protocomm request handler - * (refer to `wifi_prov_scan_handler()`) when calling `protocomm_add_endpoint()`. - */ -typedef struct wifi_prov_scan_handlers { - /** - * Handler function called when scan start command is received - * with various scan parameters : - * - * blocking (input) - If true, the function should return only - * when the scanning is finished - * - * passive (input) - If true, scan is to be started in passive - * mode (this may be slower) instead of active mode - * - * group_channels (input) - This specifies whether to scan - * all channels in one go (when zero) or perform scanning of - * channels in groups, with 120ms delay between scanning of - * consecutive groups, and the value of this parameter sets the - * number of channels in each group. This is useful when transport - * mode is SoftAP, where scanning all channels in one go may not - * give the Wi-Fi driver enough time to send out beacons, and - * hence may cause disconnection with any connected stations. - * When scanning in groups, the manager will wait for atleast - * 120ms after completing scan on a group of channels, and thus - * allow the driver to send out the beacons. For example, given - * that the total number of Wi-Fi channels is 14, then setting - * group_channels to 4, will create 5 groups, with each group - * having 3 channels, except the last one which will have - * 14 % 3 = 2 channels. So, when scan is started, the first 3 - * channels will be scanned, followed by a 120ms delay, and then - * the next 3 channels, and so on, until all the 14 channels have - * been scanned. One may need to adjust this parameter as having - * only few channels in a group may slow down the overall scan - * time, while having too many may again cause disconnection. - * Usually a value of 4 should work for most cases. Note that - * for any other mode of transport, e.g. BLE, this can be safely - * set to 0, and hence achieve the fastest overall scanning time. - * - * period_ms (input) - Scan parameter specifying how long to - * wait on each channel (in milli-seconds) - */ - esp_err_t (*scan_start)(bool blocking, bool passive, - uint8_t group_channels, uint32_t period_ms, - wifi_prov_scan_ctx_t **ctx); - - /** - * Handler function called when scan status is requested. Status - * is given the parameters : - * - * scan_finished (output) - When scan has finished this returns true - * - * result_count (output) - This gives the total number of results - * obtained till now. If scan is yet happening this number will - * keep on updating - */ - esp_err_t (*scan_status)(bool *scan_finished, - uint16_t *result_count, - wifi_prov_scan_ctx_t **ctx); - - /** - * Handler function called when scan result is requested. Parameters : - * - * scan_result - For fetching scan results. This can be called even - * if scan is still on going - * - * start_index (input) - Starting index from where to fetch the - * entries from the results list - * - * count (input) - Number of entries to fetch from the starting index - * - * entries (output) - List of entries returned. Each entry consists - * of ssid, channel and rssi information - */ - esp_err_t (*scan_result)(uint16_t result_index, - wifi_prov_scan_result_t *result, - wifi_prov_scan_ctx_t **ctx); - - /** - * Context pointer to be passed to above handler functions upon invocation - */ - wifi_prov_scan_ctx_t *ctx; -} wifi_prov_scan_handlers_t; - -/** - * @brief Handler for sending on demand Wi-Fi scan results - * - * This is to be registered as the `prov-scan` endpoint handler - * (protocomm `protocomm_req_handler_t`) using `protocomm_add_endpoint()` - */ -esp_err_t wifi_prov_scan_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, - uint8_t **outbuf, ssize_t *outlen, void *priv_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/wifi_provisioning/proto-c/wifi_config.pb-c.c b/components/wifi_provisioning/proto-c/wifi_config.pb-c.c deleted file mode 100644 index 0be6dcd86798..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_config.pb-c.c +++ /dev/null @@ -1,744 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_config.proto */ - -/* Do not generate deprecated warnings for self */ -#ifndef PROTOBUF_C__NO_DEPRECATED -#define PROTOBUF_C__NO_DEPRECATED -#endif - -#include "wifi_config.pb-c.h" -void cmd_get_status__init - (CmdGetStatus *message) -{ - static const CmdGetStatus init_value = CMD_GET_STATUS__INIT; - *message = init_value; -} -size_t cmd_get_status__get_packed_size - (const CmdGetStatus *message) -{ - assert(message->base.descriptor == &cmd_get_status__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_get_status__pack - (const CmdGetStatus *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_get_status__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_get_status__pack_to_buffer - (const CmdGetStatus *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_get_status__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdGetStatus * - cmd_get_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdGetStatus *) - protobuf_c_message_unpack (&cmd_get_status__descriptor, - allocator, len, data); -} -void cmd_get_status__free_unpacked - (CmdGetStatus *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_get_status__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_get_status__init - (RespGetStatus *message) -{ - static const RespGetStatus init_value = RESP_GET_STATUS__INIT; - *message = init_value; -} -size_t resp_get_status__get_packed_size - (const RespGetStatus *message) -{ - assert(message->base.descriptor == &resp_get_status__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_get_status__pack - (const RespGetStatus *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_get_status__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_get_status__pack_to_buffer - (const RespGetStatus *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_get_status__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespGetStatus * - resp_get_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespGetStatus *) - protobuf_c_message_unpack (&resp_get_status__descriptor, - allocator, len, data); -} -void resp_get_status__free_unpacked - (RespGetStatus *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_get_status__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void cmd_set_config__init - (CmdSetConfig *message) -{ - static const CmdSetConfig init_value = CMD_SET_CONFIG__INIT; - *message = init_value; -} -size_t cmd_set_config__get_packed_size - (const CmdSetConfig *message) -{ - assert(message->base.descriptor == &cmd_set_config__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_set_config__pack - (const CmdSetConfig *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_set_config__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_set_config__pack_to_buffer - (const CmdSetConfig *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_set_config__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdSetConfig * - cmd_set_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdSetConfig *) - protobuf_c_message_unpack (&cmd_set_config__descriptor, - allocator, len, data); -} -void cmd_set_config__free_unpacked - (CmdSetConfig *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_set_config__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_set_config__init - (RespSetConfig *message) -{ - static const RespSetConfig init_value = RESP_SET_CONFIG__INIT; - *message = init_value; -} -size_t resp_set_config__get_packed_size - (const RespSetConfig *message) -{ - assert(message->base.descriptor == &resp_set_config__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_set_config__pack - (const RespSetConfig *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_set_config__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_set_config__pack_to_buffer - (const RespSetConfig *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_set_config__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespSetConfig * - resp_set_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespSetConfig *) - protobuf_c_message_unpack (&resp_set_config__descriptor, - allocator, len, data); -} -void resp_set_config__free_unpacked - (RespSetConfig *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_set_config__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void cmd_apply_config__init - (CmdApplyConfig *message) -{ - static const CmdApplyConfig init_value = CMD_APPLY_CONFIG__INIT; - *message = init_value; -} -size_t cmd_apply_config__get_packed_size - (const CmdApplyConfig *message) -{ - assert(message->base.descriptor == &cmd_apply_config__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_apply_config__pack - (const CmdApplyConfig *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_apply_config__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_apply_config__pack_to_buffer - (const CmdApplyConfig *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_apply_config__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdApplyConfig * - cmd_apply_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdApplyConfig *) - protobuf_c_message_unpack (&cmd_apply_config__descriptor, - allocator, len, data); -} -void cmd_apply_config__free_unpacked - (CmdApplyConfig *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_apply_config__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_apply_config__init - (RespApplyConfig *message) -{ - static const RespApplyConfig init_value = RESP_APPLY_CONFIG__INIT; - *message = init_value; -} -size_t resp_apply_config__get_packed_size - (const RespApplyConfig *message) -{ - assert(message->base.descriptor == &resp_apply_config__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_apply_config__pack - (const RespApplyConfig *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_apply_config__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_apply_config__pack_to_buffer - (const RespApplyConfig *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_apply_config__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespApplyConfig * - resp_apply_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespApplyConfig *) - protobuf_c_message_unpack (&resp_apply_config__descriptor, - allocator, len, data); -} -void resp_apply_config__free_unpacked - (RespApplyConfig *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_apply_config__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void wi_fi_config_payload__init - (WiFiConfigPayload *message) -{ - static const WiFiConfigPayload init_value = WI_FI_CONFIG_PAYLOAD__INIT; - *message = init_value; -} -size_t wi_fi_config_payload__get_packed_size - (const WiFiConfigPayload *message) -{ - assert(message->base.descriptor == &wi_fi_config_payload__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t wi_fi_config_payload__pack - (const WiFiConfigPayload *message, - uint8_t *out) -{ - assert(message->base.descriptor == &wi_fi_config_payload__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t wi_fi_config_payload__pack_to_buffer - (const WiFiConfigPayload *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &wi_fi_config_payload__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -WiFiConfigPayload * - wi_fi_config_payload__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (WiFiConfigPayload *) - protobuf_c_message_unpack (&wi_fi_config_payload__descriptor, - allocator, len, data); -} -void wi_fi_config_payload__free_unpacked - (WiFiConfigPayload *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &wi_fi_config_payload__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -#define cmd_get_status__field_descriptors NULL -#define cmd_get_status__field_indices_by_name NULL -#define cmd_get_status__number_ranges NULL -const ProtobufCMessageDescriptor cmd_get_status__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdGetStatus", - "CmdGetStatus", - "CmdGetStatus", - "", - sizeof(CmdGetStatus), - 0, - cmd_get_status__field_descriptors, - cmd_get_status__field_indices_by_name, - 0, cmd_get_status__number_ranges, - (ProtobufCMessageInit) cmd_get_status__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor resp_get_status__field_descriptors[4] = -{ - { - "status", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(RespGetStatus, status), - &status__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "sta_state", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(RespGetStatus, sta_state), - &wifi_station_state__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "fail_reason", - 10, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - offsetof(RespGetStatus, state_case), - offsetof(RespGetStatus, fail_reason), - &wifi_connect_failed_reason__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "connected", - 11, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(RespGetStatus, state_case), - offsetof(RespGetStatus, connected), - &wifi_connected_state__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned resp_get_status__field_indices_by_name[] = { - 3, /* field[3] = connected */ - 2, /* field[2] = fail_reason */ - 1, /* field[1] = sta_state */ - 0, /* field[0] = status */ -}; -static const ProtobufCIntRange resp_get_status__number_ranges[2 + 1] = -{ - { 1, 0 }, - { 10, 2 }, - { 0, 4 } -}; -const ProtobufCMessageDescriptor resp_get_status__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespGetStatus", - "RespGetStatus", - "RespGetStatus", - "", - sizeof(RespGetStatus), - 4, - resp_get_status__field_descriptors, - resp_get_status__field_indices_by_name, - 2, resp_get_status__number_ranges, - (ProtobufCMessageInit) resp_get_status__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor cmd_set_config__field_descriptors[4] = -{ - { - "ssid", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(CmdSetConfig, ssid), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "passphrase", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(CmdSetConfig, passphrase), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "bssid", - 3, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(CmdSetConfig, bssid), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "channel", - 4, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_INT32, - 0, /* quantifier_offset */ - offsetof(CmdSetConfig, channel), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned cmd_set_config__field_indices_by_name[] = { - 2, /* field[2] = bssid */ - 3, /* field[3] = channel */ - 1, /* field[1] = passphrase */ - 0, /* field[0] = ssid */ -}; -static const ProtobufCIntRange cmd_set_config__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 4 } -}; -const ProtobufCMessageDescriptor cmd_set_config__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdSetConfig", - "CmdSetConfig", - "CmdSetConfig", - "", - sizeof(CmdSetConfig), - 4, - cmd_set_config__field_descriptors, - cmd_set_config__field_indices_by_name, - 1, cmd_set_config__number_ranges, - (ProtobufCMessageInit) cmd_set_config__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor resp_set_config__field_descriptors[1] = -{ - { - "status", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(RespSetConfig, status), - &status__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned resp_set_config__field_indices_by_name[] = { - 0, /* field[0] = status */ -}; -static const ProtobufCIntRange resp_set_config__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 1 } -}; -const ProtobufCMessageDescriptor resp_set_config__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespSetConfig", - "RespSetConfig", - "RespSetConfig", - "", - sizeof(RespSetConfig), - 1, - resp_set_config__field_descriptors, - resp_set_config__field_indices_by_name, - 1, resp_set_config__number_ranges, - (ProtobufCMessageInit) resp_set_config__init, - NULL,NULL,NULL /* reserved[123] */ -}; -#define cmd_apply_config__field_descriptors NULL -#define cmd_apply_config__field_indices_by_name NULL -#define cmd_apply_config__number_ranges NULL -const ProtobufCMessageDescriptor cmd_apply_config__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdApplyConfig", - "CmdApplyConfig", - "CmdApplyConfig", - "", - sizeof(CmdApplyConfig), - 0, - cmd_apply_config__field_descriptors, - cmd_apply_config__field_indices_by_name, - 0, cmd_apply_config__number_ranges, - (ProtobufCMessageInit) cmd_apply_config__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor resp_apply_config__field_descriptors[1] = -{ - { - "status", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(RespApplyConfig, status), - &status__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned resp_apply_config__field_indices_by_name[] = { - 0, /* field[0] = status */ -}; -static const ProtobufCIntRange resp_apply_config__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 1 } -}; -const ProtobufCMessageDescriptor resp_apply_config__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespApplyConfig", - "RespApplyConfig", - "RespApplyConfig", - "", - sizeof(RespApplyConfig), - 1, - resp_apply_config__field_descriptors, - resp_apply_config__field_indices_by_name, - 1, resp_apply_config__number_ranges, - (ProtobufCMessageInit) resp_apply_config__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor wi_fi_config_payload__field_descriptors[7] = -{ - { - "msg", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WiFiConfigPayload, msg), - &wi_fi_config_msg_type__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_get_status", - 10, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiConfigPayload, payload_case), - offsetof(WiFiConfigPayload, cmd_get_status), - &cmd_get_status__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_get_status", - 11, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiConfigPayload, payload_case), - offsetof(WiFiConfigPayload, resp_get_status), - &resp_get_status__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_set_config", - 12, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiConfigPayload, payload_case), - offsetof(WiFiConfigPayload, cmd_set_config), - &cmd_set_config__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_set_config", - 13, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiConfigPayload, payload_case), - offsetof(WiFiConfigPayload, resp_set_config), - &resp_set_config__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_apply_config", - 14, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiConfigPayload, payload_case), - offsetof(WiFiConfigPayload, cmd_apply_config), - &cmd_apply_config__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_apply_config", - 15, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiConfigPayload, payload_case), - offsetof(WiFiConfigPayload, resp_apply_config), - &resp_apply_config__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned wi_fi_config_payload__field_indices_by_name[] = { - 5, /* field[5] = cmd_apply_config */ - 1, /* field[1] = cmd_get_status */ - 3, /* field[3] = cmd_set_config */ - 0, /* field[0] = msg */ - 6, /* field[6] = resp_apply_config */ - 2, /* field[2] = resp_get_status */ - 4, /* field[4] = resp_set_config */ -}; -static const ProtobufCIntRange wi_fi_config_payload__number_ranges[2 + 1] = -{ - { 1, 0 }, - { 10, 1 }, - { 0, 7 } -}; -const ProtobufCMessageDescriptor wi_fi_config_payload__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "WiFiConfigPayload", - "WiFiConfigPayload", - "WiFiConfigPayload", - "", - sizeof(WiFiConfigPayload), - 7, - wi_fi_config_payload__field_descriptors, - wi_fi_config_payload__field_indices_by_name, - 2, wi_fi_config_payload__number_ranges, - (ProtobufCMessageInit) wi_fi_config_payload__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCEnumValue wi_fi_config_msg_type__enum_values_by_number[6] = -{ - { "TypeCmdGetStatus", "WI_FI_CONFIG_MSG_TYPE__TypeCmdGetStatus", 0 }, - { "TypeRespGetStatus", "WI_FI_CONFIG_MSG_TYPE__TypeRespGetStatus", 1 }, - { "TypeCmdSetConfig", "WI_FI_CONFIG_MSG_TYPE__TypeCmdSetConfig", 2 }, - { "TypeRespSetConfig", "WI_FI_CONFIG_MSG_TYPE__TypeRespSetConfig", 3 }, - { "TypeCmdApplyConfig", "WI_FI_CONFIG_MSG_TYPE__TypeCmdApplyConfig", 4 }, - { "TypeRespApplyConfig", "WI_FI_CONFIG_MSG_TYPE__TypeRespApplyConfig", 5 }, -}; -static const ProtobufCIntRange wi_fi_config_msg_type__value_ranges[] = { -{0, 0},{0, 6} -}; -static const ProtobufCEnumValueIndex wi_fi_config_msg_type__enum_values_by_name[6] = -{ - { "TypeCmdApplyConfig", 4 }, - { "TypeCmdGetStatus", 0 }, - { "TypeCmdSetConfig", 2 }, - { "TypeRespApplyConfig", 5 }, - { "TypeRespGetStatus", 1 }, - { "TypeRespSetConfig", 3 }, -}; -const ProtobufCEnumDescriptor wi_fi_config_msg_type__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "WiFiConfigMsgType", - "WiFiConfigMsgType", - "WiFiConfigMsgType", - "", - 6, - wi_fi_config_msg_type__enum_values_by_number, - 6, - wi_fi_config_msg_type__enum_values_by_name, - 1, - wi_fi_config_msg_type__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; diff --git a/components/wifi_provisioning/proto-c/wifi_config.pb-c.h b/components/wifi_provisioning/proto-c/wifi_config.pb-c.h deleted file mode 100644 index 3e293f23be03..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_config.pb-c.h +++ /dev/null @@ -1,321 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_config.proto */ - -#ifndef PROTOBUF_C_wifi_5fconfig_2eproto__INCLUDED -#define PROTOBUF_C_wifi_5fconfig_2eproto__INCLUDED - -#include - -PROTOBUF_C__BEGIN_DECLS - -#if PROTOBUF_C_VERSION_NUMBER < 1003000 -# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. -#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION -# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. -#endif - -#include "constants.pb-c.h" -#include "wifi_constants.pb-c.h" - -typedef struct CmdGetStatus CmdGetStatus; -typedef struct RespGetStatus RespGetStatus; -typedef struct CmdSetConfig CmdSetConfig; -typedef struct RespSetConfig RespSetConfig; -typedef struct CmdApplyConfig CmdApplyConfig; -typedef struct RespApplyConfig RespApplyConfig; -typedef struct WiFiConfigPayload WiFiConfigPayload; - - -/* --- enums --- */ - -typedef enum _WiFiConfigMsgType { - WI_FI_CONFIG_MSG_TYPE__TypeCmdGetStatus = 0, - WI_FI_CONFIG_MSG_TYPE__TypeRespGetStatus = 1, - WI_FI_CONFIG_MSG_TYPE__TypeCmdSetConfig = 2, - WI_FI_CONFIG_MSG_TYPE__TypeRespSetConfig = 3, - WI_FI_CONFIG_MSG_TYPE__TypeCmdApplyConfig = 4, - WI_FI_CONFIG_MSG_TYPE__TypeRespApplyConfig = 5 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WI_FI_CONFIG_MSG_TYPE) -} WiFiConfigMsgType; - -/* --- messages --- */ - -struct CmdGetStatus -{ - ProtobufCMessage base; -}; -#define CMD_GET_STATUS__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_get_status__descriptor) \ - } - - -typedef enum { - RESP_GET_STATUS__STATE__NOT_SET = 0, - RESP_GET_STATUS__STATE_FAIL_REASON = 10, - RESP_GET_STATUS__STATE_CONNECTED = 11 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(RESP_GET_STATUS__STATE__CASE) -} RespGetStatus__StateCase; - -struct RespGetStatus -{ - ProtobufCMessage base; - Status status; - WifiStationState sta_state; - RespGetStatus__StateCase state_case; - union { - WifiConnectFailedReason fail_reason; - WifiConnectedState *connected; - }; -}; -#define RESP_GET_STATUS__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_get_status__descriptor) \ - , STATUS__Success, WIFI_STATION_STATE__Connected, RESP_GET_STATUS__STATE__NOT_SET, {0} } - - -struct CmdSetConfig -{ - ProtobufCMessage base; - ProtobufCBinaryData ssid; - ProtobufCBinaryData passphrase; - ProtobufCBinaryData bssid; - int32_t channel; -}; -#define CMD_SET_CONFIG__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_set_config__descriptor) \ - , {0,NULL}, {0,NULL}, {0,NULL}, 0 } - - -struct RespSetConfig -{ - ProtobufCMessage base; - Status status; -}; -#define RESP_SET_CONFIG__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_set_config__descriptor) \ - , STATUS__Success } - - -struct CmdApplyConfig -{ - ProtobufCMessage base; -}; -#define CMD_APPLY_CONFIG__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_apply_config__descriptor) \ - } - - -struct RespApplyConfig -{ - ProtobufCMessage base; - Status status; -}; -#define RESP_APPLY_CONFIG__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_apply_config__descriptor) \ - , STATUS__Success } - - -typedef enum { - WI_FI_CONFIG_PAYLOAD__PAYLOAD__NOT_SET = 0, - WI_FI_CONFIG_PAYLOAD__PAYLOAD_CMD_GET_STATUS = 10, - WI_FI_CONFIG_PAYLOAD__PAYLOAD_RESP_GET_STATUS = 11, - WI_FI_CONFIG_PAYLOAD__PAYLOAD_CMD_SET_CONFIG = 12, - WI_FI_CONFIG_PAYLOAD__PAYLOAD_RESP_SET_CONFIG = 13, - WI_FI_CONFIG_PAYLOAD__PAYLOAD_CMD_APPLY_CONFIG = 14, - WI_FI_CONFIG_PAYLOAD__PAYLOAD_RESP_APPLY_CONFIG = 15 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WI_FI_CONFIG_PAYLOAD__PAYLOAD__CASE) -} WiFiConfigPayload__PayloadCase; - -struct WiFiConfigPayload -{ - ProtobufCMessage base; - WiFiConfigMsgType msg; - WiFiConfigPayload__PayloadCase payload_case; - union { - CmdGetStatus *cmd_get_status; - RespGetStatus *resp_get_status; - CmdSetConfig *cmd_set_config; - RespSetConfig *resp_set_config; - CmdApplyConfig *cmd_apply_config; - RespApplyConfig *resp_apply_config; - }; -}; -#define WI_FI_CONFIG_PAYLOAD__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&wi_fi_config_payload__descriptor) \ - , WI_FI_CONFIG_MSG_TYPE__TypeCmdGetStatus, WI_FI_CONFIG_PAYLOAD__PAYLOAD__NOT_SET, {0} } - - -/* CmdGetStatus methods */ -void cmd_get_status__init - (CmdGetStatus *message); -size_t cmd_get_status__get_packed_size - (const CmdGetStatus *message); -size_t cmd_get_status__pack - (const CmdGetStatus *message, - uint8_t *out); -size_t cmd_get_status__pack_to_buffer - (const CmdGetStatus *message, - ProtobufCBuffer *buffer); -CmdGetStatus * - cmd_get_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_get_status__free_unpacked - (CmdGetStatus *message, - ProtobufCAllocator *allocator); -/* RespGetStatus methods */ -void resp_get_status__init - (RespGetStatus *message); -size_t resp_get_status__get_packed_size - (const RespGetStatus *message); -size_t resp_get_status__pack - (const RespGetStatus *message, - uint8_t *out); -size_t resp_get_status__pack_to_buffer - (const RespGetStatus *message, - ProtobufCBuffer *buffer); -RespGetStatus * - resp_get_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_get_status__free_unpacked - (RespGetStatus *message, - ProtobufCAllocator *allocator); -/* CmdSetConfig methods */ -void cmd_set_config__init - (CmdSetConfig *message); -size_t cmd_set_config__get_packed_size - (const CmdSetConfig *message); -size_t cmd_set_config__pack - (const CmdSetConfig *message, - uint8_t *out); -size_t cmd_set_config__pack_to_buffer - (const CmdSetConfig *message, - ProtobufCBuffer *buffer); -CmdSetConfig * - cmd_set_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_set_config__free_unpacked - (CmdSetConfig *message, - ProtobufCAllocator *allocator); -/* RespSetConfig methods */ -void resp_set_config__init - (RespSetConfig *message); -size_t resp_set_config__get_packed_size - (const RespSetConfig *message); -size_t resp_set_config__pack - (const RespSetConfig *message, - uint8_t *out); -size_t resp_set_config__pack_to_buffer - (const RespSetConfig *message, - ProtobufCBuffer *buffer); -RespSetConfig * - resp_set_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_set_config__free_unpacked - (RespSetConfig *message, - ProtobufCAllocator *allocator); -/* CmdApplyConfig methods */ -void cmd_apply_config__init - (CmdApplyConfig *message); -size_t cmd_apply_config__get_packed_size - (const CmdApplyConfig *message); -size_t cmd_apply_config__pack - (const CmdApplyConfig *message, - uint8_t *out); -size_t cmd_apply_config__pack_to_buffer - (const CmdApplyConfig *message, - ProtobufCBuffer *buffer); -CmdApplyConfig * - cmd_apply_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_apply_config__free_unpacked - (CmdApplyConfig *message, - ProtobufCAllocator *allocator); -/* RespApplyConfig methods */ -void resp_apply_config__init - (RespApplyConfig *message); -size_t resp_apply_config__get_packed_size - (const RespApplyConfig *message); -size_t resp_apply_config__pack - (const RespApplyConfig *message, - uint8_t *out); -size_t resp_apply_config__pack_to_buffer - (const RespApplyConfig *message, - ProtobufCBuffer *buffer); -RespApplyConfig * - resp_apply_config__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_apply_config__free_unpacked - (RespApplyConfig *message, - ProtobufCAllocator *allocator); -/* WiFiConfigPayload methods */ -void wi_fi_config_payload__init - (WiFiConfigPayload *message); -size_t wi_fi_config_payload__get_packed_size - (const WiFiConfigPayload *message); -size_t wi_fi_config_payload__pack - (const WiFiConfigPayload *message, - uint8_t *out); -size_t wi_fi_config_payload__pack_to_buffer - (const WiFiConfigPayload *message, - ProtobufCBuffer *buffer); -WiFiConfigPayload * - wi_fi_config_payload__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void wi_fi_config_payload__free_unpacked - (WiFiConfigPayload *message, - ProtobufCAllocator *allocator); -/* --- per-message closures --- */ - -typedef void (*CmdGetStatus_Closure) - (const CmdGetStatus *message, - void *closure_data); -typedef void (*RespGetStatus_Closure) - (const RespGetStatus *message, - void *closure_data); -typedef void (*CmdSetConfig_Closure) - (const CmdSetConfig *message, - void *closure_data); -typedef void (*RespSetConfig_Closure) - (const RespSetConfig *message, - void *closure_data); -typedef void (*CmdApplyConfig_Closure) - (const CmdApplyConfig *message, - void *closure_data); -typedef void (*RespApplyConfig_Closure) - (const RespApplyConfig *message, - void *closure_data); -typedef void (*WiFiConfigPayload_Closure) - (const WiFiConfigPayload *message, - void *closure_data); - -/* --- services --- */ - - -/* --- descriptors --- */ - -extern const ProtobufCEnumDescriptor wi_fi_config_msg_type__descriptor; -extern const ProtobufCMessageDescriptor cmd_get_status__descriptor; -extern const ProtobufCMessageDescriptor resp_get_status__descriptor; -extern const ProtobufCMessageDescriptor cmd_set_config__descriptor; -extern const ProtobufCMessageDescriptor resp_set_config__descriptor; -extern const ProtobufCMessageDescriptor cmd_apply_config__descriptor; -extern const ProtobufCMessageDescriptor resp_apply_config__descriptor; -extern const ProtobufCMessageDescriptor wi_fi_config_payload__descriptor; - -PROTOBUF_C__END_DECLS - - -#endif /* PROTOBUF_C_wifi_5fconfig_2eproto__INCLUDED */ diff --git a/components/wifi_provisioning/proto-c/wifi_constants.pb-c.c b/components/wifi_provisioning/proto-c/wifi_constants.pb-c.c deleted file mode 100644 index aec0f4182041..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_constants.pb-c.c +++ /dev/null @@ -1,244 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_constants.proto */ - -/* Do not generate deprecated warnings for self */ -#ifndef PROTOBUF_C__NO_DEPRECATED -#define PROTOBUF_C__NO_DEPRECATED -#endif - -#include "wifi_constants.pb-c.h" -void wifi_connected_state__init - (WifiConnectedState *message) -{ - static const WifiConnectedState init_value = WIFI_CONNECTED_STATE__INIT; - *message = init_value; -} -size_t wifi_connected_state__get_packed_size - (const WifiConnectedState *message) -{ - assert(message->base.descriptor == &wifi_connected_state__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t wifi_connected_state__pack - (const WifiConnectedState *message, - uint8_t *out) -{ - assert(message->base.descriptor == &wifi_connected_state__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t wifi_connected_state__pack_to_buffer - (const WifiConnectedState *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &wifi_connected_state__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -WifiConnectedState * - wifi_connected_state__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (WifiConnectedState *) - protobuf_c_message_unpack (&wifi_connected_state__descriptor, - allocator, len, data); -} -void wifi_connected_state__free_unpacked - (WifiConnectedState *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &wifi_connected_state__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -static const ProtobufCFieldDescriptor wifi_connected_state__field_descriptors[5] = -{ - { - "ip4_addr", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(WifiConnectedState, ip4_addr), - NULL, - &protobuf_c_empty_string, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "auth_mode", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WifiConnectedState, auth_mode), - &wifi_auth_mode__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "ssid", - 3, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(WifiConnectedState, ssid), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "bssid", - 4, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(WifiConnectedState, bssid), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "channel", - 5, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_INT32, - 0, /* quantifier_offset */ - offsetof(WifiConnectedState, channel), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned wifi_connected_state__field_indices_by_name[] = { - 1, /* field[1] = auth_mode */ - 3, /* field[3] = bssid */ - 4, /* field[4] = channel */ - 0, /* field[0] = ip4_addr */ - 2, /* field[2] = ssid */ -}; -static const ProtobufCIntRange wifi_connected_state__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 5 } -}; -const ProtobufCMessageDescriptor wifi_connected_state__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "WifiConnectedState", - "WifiConnectedState", - "WifiConnectedState", - "", - sizeof(WifiConnectedState), - 5, - wifi_connected_state__field_descriptors, - wifi_connected_state__field_indices_by_name, - 1, wifi_connected_state__number_ranges, - (ProtobufCMessageInit) wifi_connected_state__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCEnumValue wifi_station_state__enum_values_by_number[4] = -{ - { "Connected", "WIFI_STATION_STATE__Connected", 0 }, - { "Connecting", "WIFI_STATION_STATE__Connecting", 1 }, - { "Disconnected", "WIFI_STATION_STATE__Disconnected", 2 }, - { "ConnectionFailed", "WIFI_STATION_STATE__ConnectionFailed", 3 }, -}; -static const ProtobufCIntRange wifi_station_state__value_ranges[] = { -{0, 0},{0, 4} -}; -static const ProtobufCEnumValueIndex wifi_station_state__enum_values_by_name[4] = -{ - { "Connected", 0 }, - { "Connecting", 1 }, - { "ConnectionFailed", 3 }, - { "Disconnected", 2 }, -}; -const ProtobufCEnumDescriptor wifi_station_state__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "WifiStationState", - "WifiStationState", - "WifiStationState", - "", - 4, - wifi_station_state__enum_values_by_number, - 4, - wifi_station_state__enum_values_by_name, - 1, - wifi_station_state__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; -static const ProtobufCEnumValue wifi_connect_failed_reason__enum_values_by_number[2] = -{ - { "AuthError", "WIFI_CONNECT_FAILED_REASON__AuthError", 0 }, - { "NetworkNotFound", "WIFI_CONNECT_FAILED_REASON__NetworkNotFound", 1 }, -}; -static const ProtobufCIntRange wifi_connect_failed_reason__value_ranges[] = { -{0, 0},{0, 2} -}; -static const ProtobufCEnumValueIndex wifi_connect_failed_reason__enum_values_by_name[2] = -{ - { "AuthError", 0 }, - { "NetworkNotFound", 1 }, -}; -const ProtobufCEnumDescriptor wifi_connect_failed_reason__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "WifiConnectFailedReason", - "WifiConnectFailedReason", - "WifiConnectFailedReason", - "", - 2, - wifi_connect_failed_reason__enum_values_by_number, - 2, - wifi_connect_failed_reason__enum_values_by_name, - 1, - wifi_connect_failed_reason__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; -static const ProtobufCEnumValue wifi_auth_mode__enum_values_by_number[8] = -{ - { "Open", "WIFI_AUTH_MODE__Open", 0 }, - { "WEP", "WIFI_AUTH_MODE__WEP", 1 }, - { "WPA_PSK", "WIFI_AUTH_MODE__WPA_PSK", 2 }, - { "WPA2_PSK", "WIFI_AUTH_MODE__WPA2_PSK", 3 }, - { "WPA_WPA2_PSK", "WIFI_AUTH_MODE__WPA_WPA2_PSK", 4 }, - { "WPA2_ENTERPRISE", "WIFI_AUTH_MODE__WPA2_ENTERPRISE", 5 }, - { "WPA3_PSK", "WIFI_AUTH_MODE__WPA3_PSK", 6 }, - { "WPA2_WPA3_PSK", "WIFI_AUTH_MODE__WPA2_WPA3_PSK", 7 }, -}; -static const ProtobufCIntRange wifi_auth_mode__value_ranges[] = { -{0, 0},{0, 8} -}; -static const ProtobufCEnumValueIndex wifi_auth_mode__enum_values_by_name[8] = -{ - { "Open", 0 }, - { "WEP", 1 }, - { "WPA2_ENTERPRISE", 5 }, - { "WPA2_PSK", 3 }, - { "WPA2_WPA3_PSK", 7 }, - { "WPA3_PSK", 6 }, - { "WPA_PSK", 2 }, - { "WPA_WPA2_PSK", 4 }, -}; -const ProtobufCEnumDescriptor wifi_auth_mode__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "WifiAuthMode", - "WifiAuthMode", - "WifiAuthMode", - "", - 8, - wifi_auth_mode__enum_values_by_number, - 8, - wifi_auth_mode__enum_values_by_name, - 1, - wifi_auth_mode__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; diff --git a/components/wifi_provisioning/proto-c/wifi_constants.pb-c.h b/components/wifi_provisioning/proto-c/wifi_constants.pb-c.h deleted file mode 100644 index abebe2956b1d..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_constants.pb-c.h +++ /dev/null @@ -1,101 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_constants.proto */ - -#ifndef PROTOBUF_C_wifi_5fconstants_2eproto__INCLUDED -#define PROTOBUF_C_wifi_5fconstants_2eproto__INCLUDED - -#include - -PROTOBUF_C__BEGIN_DECLS - -#if PROTOBUF_C_VERSION_NUMBER < 1003000 -# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. -#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION -# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. -#endif - - -typedef struct WifiConnectedState WifiConnectedState; - - -/* --- enums --- */ - -typedef enum _WifiStationState { - WIFI_STATION_STATE__Connected = 0, - WIFI_STATION_STATE__Connecting = 1, - WIFI_STATION_STATE__Disconnected = 2, - WIFI_STATION_STATE__ConnectionFailed = 3 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WIFI_STATION_STATE) -} WifiStationState; -typedef enum _WifiConnectFailedReason { - WIFI_CONNECT_FAILED_REASON__AuthError = 0, - WIFI_CONNECT_FAILED_REASON__NetworkNotFound = 1 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WIFI_CONNECT_FAILED_REASON) -} WifiConnectFailedReason; -typedef enum _WifiAuthMode { - WIFI_AUTH_MODE__Open = 0, - WIFI_AUTH_MODE__WEP = 1, - WIFI_AUTH_MODE__WPA_PSK = 2, - WIFI_AUTH_MODE__WPA2_PSK = 3, - WIFI_AUTH_MODE__WPA_WPA2_PSK = 4, - WIFI_AUTH_MODE__WPA2_ENTERPRISE = 5, - WIFI_AUTH_MODE__WPA3_PSK = 6, - WIFI_AUTH_MODE__WPA2_WPA3_PSK = 7 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WIFI_AUTH_MODE) -} WifiAuthMode; - -/* --- messages --- */ - -struct WifiConnectedState -{ - ProtobufCMessage base; - char *ip4_addr; - WifiAuthMode auth_mode; - ProtobufCBinaryData ssid; - ProtobufCBinaryData bssid; - int32_t channel; -}; -#define WIFI_CONNECTED_STATE__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&wifi_connected_state__descriptor) \ - , (char *)protobuf_c_empty_string, WIFI_AUTH_MODE__Open, {0,NULL}, {0,NULL}, 0 } - - -/* WifiConnectedState methods */ -void wifi_connected_state__init - (WifiConnectedState *message); -size_t wifi_connected_state__get_packed_size - (const WifiConnectedState *message); -size_t wifi_connected_state__pack - (const WifiConnectedState *message, - uint8_t *out); -size_t wifi_connected_state__pack_to_buffer - (const WifiConnectedState *message, - ProtobufCBuffer *buffer); -WifiConnectedState * - wifi_connected_state__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void wifi_connected_state__free_unpacked - (WifiConnectedState *message, - ProtobufCAllocator *allocator); -/* --- per-message closures --- */ - -typedef void (*WifiConnectedState_Closure) - (const WifiConnectedState *message, - void *closure_data); - -/* --- services --- */ - - -/* --- descriptors --- */ - -extern const ProtobufCEnumDescriptor wifi_station_state__descriptor; -extern const ProtobufCEnumDescriptor wifi_connect_failed_reason__descriptor; -extern const ProtobufCEnumDescriptor wifi_auth_mode__descriptor; -extern const ProtobufCMessageDescriptor wifi_connected_state__descriptor; - -PROTOBUF_C__END_DECLS - - -#endif /* PROTOBUF_C_wifi_5fconstants_2eproto__INCLUDED */ diff --git a/components/wifi_provisioning/proto-c/wifi_ctrl.pb-c.c b/components/wifi_provisioning/proto-c/wifi_ctrl.pb-c.c deleted file mode 100644 index a1a0fbf84aa3..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_ctrl.pb-c.c +++ /dev/null @@ -1,444 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_ctrl.proto */ - -/* Do not generate deprecated warnings for self */ -#ifndef PROTOBUF_C__NO_DEPRECATED -#define PROTOBUF_C__NO_DEPRECATED -#endif - -#include "wifi_ctrl.pb-c.h" -void cmd_ctrl_reset__init - (CmdCtrlReset *message) -{ - static const CmdCtrlReset init_value = CMD_CTRL_RESET__INIT; - *message = init_value; -} -size_t cmd_ctrl_reset__get_packed_size - (const CmdCtrlReset *message) -{ - assert(message->base.descriptor == &cmd_ctrl_reset__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_ctrl_reset__pack - (const CmdCtrlReset *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_ctrl_reset__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_ctrl_reset__pack_to_buffer - (const CmdCtrlReset *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_ctrl_reset__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdCtrlReset * - cmd_ctrl_reset__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdCtrlReset *) - protobuf_c_message_unpack (&cmd_ctrl_reset__descriptor, - allocator, len, data); -} -void cmd_ctrl_reset__free_unpacked - (CmdCtrlReset *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_ctrl_reset__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_ctrl_reset__init - (RespCtrlReset *message) -{ - static const RespCtrlReset init_value = RESP_CTRL_RESET__INIT; - *message = init_value; -} -size_t resp_ctrl_reset__get_packed_size - (const RespCtrlReset *message) -{ - assert(message->base.descriptor == &resp_ctrl_reset__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_ctrl_reset__pack - (const RespCtrlReset *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_ctrl_reset__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_ctrl_reset__pack_to_buffer - (const RespCtrlReset *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_ctrl_reset__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespCtrlReset * - resp_ctrl_reset__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespCtrlReset *) - protobuf_c_message_unpack (&resp_ctrl_reset__descriptor, - allocator, len, data); -} -void resp_ctrl_reset__free_unpacked - (RespCtrlReset *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_ctrl_reset__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void cmd_ctrl_reprov__init - (CmdCtrlReprov *message) -{ - static const CmdCtrlReprov init_value = CMD_CTRL_REPROV__INIT; - *message = init_value; -} -size_t cmd_ctrl_reprov__get_packed_size - (const CmdCtrlReprov *message) -{ - assert(message->base.descriptor == &cmd_ctrl_reprov__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_ctrl_reprov__pack - (const CmdCtrlReprov *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_ctrl_reprov__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_ctrl_reprov__pack_to_buffer - (const CmdCtrlReprov *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_ctrl_reprov__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdCtrlReprov * - cmd_ctrl_reprov__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdCtrlReprov *) - protobuf_c_message_unpack (&cmd_ctrl_reprov__descriptor, - allocator, len, data); -} -void cmd_ctrl_reprov__free_unpacked - (CmdCtrlReprov *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_ctrl_reprov__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_ctrl_reprov__init - (RespCtrlReprov *message) -{ - static const RespCtrlReprov init_value = RESP_CTRL_REPROV__INIT; - *message = init_value; -} -size_t resp_ctrl_reprov__get_packed_size - (const RespCtrlReprov *message) -{ - assert(message->base.descriptor == &resp_ctrl_reprov__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_ctrl_reprov__pack - (const RespCtrlReprov *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_ctrl_reprov__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_ctrl_reprov__pack_to_buffer - (const RespCtrlReprov *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_ctrl_reprov__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespCtrlReprov * - resp_ctrl_reprov__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespCtrlReprov *) - protobuf_c_message_unpack (&resp_ctrl_reprov__descriptor, - allocator, len, data); -} -void resp_ctrl_reprov__free_unpacked - (RespCtrlReprov *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_ctrl_reprov__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void wi_fi_ctrl_payload__init - (WiFiCtrlPayload *message) -{ - static const WiFiCtrlPayload init_value = WI_FI_CTRL_PAYLOAD__INIT; - *message = init_value; -} -size_t wi_fi_ctrl_payload__get_packed_size - (const WiFiCtrlPayload *message) -{ - assert(message->base.descriptor == &wi_fi_ctrl_payload__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t wi_fi_ctrl_payload__pack - (const WiFiCtrlPayload *message, - uint8_t *out) -{ - assert(message->base.descriptor == &wi_fi_ctrl_payload__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t wi_fi_ctrl_payload__pack_to_buffer - (const WiFiCtrlPayload *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &wi_fi_ctrl_payload__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -WiFiCtrlPayload * - wi_fi_ctrl_payload__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (WiFiCtrlPayload *) - protobuf_c_message_unpack (&wi_fi_ctrl_payload__descriptor, - allocator, len, data); -} -void wi_fi_ctrl_payload__free_unpacked - (WiFiCtrlPayload *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &wi_fi_ctrl_payload__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -#define cmd_ctrl_reset__field_descriptors NULL -#define cmd_ctrl_reset__field_indices_by_name NULL -#define cmd_ctrl_reset__number_ranges NULL -const ProtobufCMessageDescriptor cmd_ctrl_reset__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdCtrlReset", - "CmdCtrlReset", - "CmdCtrlReset", - "", - sizeof(CmdCtrlReset), - 0, - cmd_ctrl_reset__field_descriptors, - cmd_ctrl_reset__field_indices_by_name, - 0, cmd_ctrl_reset__number_ranges, - (ProtobufCMessageInit) cmd_ctrl_reset__init, - NULL,NULL,NULL /* reserved[123] */ -}; -#define resp_ctrl_reset__field_descriptors NULL -#define resp_ctrl_reset__field_indices_by_name NULL -#define resp_ctrl_reset__number_ranges NULL -const ProtobufCMessageDescriptor resp_ctrl_reset__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespCtrlReset", - "RespCtrlReset", - "RespCtrlReset", - "", - sizeof(RespCtrlReset), - 0, - resp_ctrl_reset__field_descriptors, - resp_ctrl_reset__field_indices_by_name, - 0, resp_ctrl_reset__number_ranges, - (ProtobufCMessageInit) resp_ctrl_reset__init, - NULL,NULL,NULL /* reserved[123] */ -}; -#define cmd_ctrl_reprov__field_descriptors NULL -#define cmd_ctrl_reprov__field_indices_by_name NULL -#define cmd_ctrl_reprov__number_ranges NULL -const ProtobufCMessageDescriptor cmd_ctrl_reprov__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdCtrlReprov", - "CmdCtrlReprov", - "CmdCtrlReprov", - "", - sizeof(CmdCtrlReprov), - 0, - cmd_ctrl_reprov__field_descriptors, - cmd_ctrl_reprov__field_indices_by_name, - 0, cmd_ctrl_reprov__number_ranges, - (ProtobufCMessageInit) cmd_ctrl_reprov__init, - NULL,NULL,NULL /* reserved[123] */ -}; -#define resp_ctrl_reprov__field_descriptors NULL -#define resp_ctrl_reprov__field_indices_by_name NULL -#define resp_ctrl_reprov__number_ranges NULL -const ProtobufCMessageDescriptor resp_ctrl_reprov__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespCtrlReprov", - "RespCtrlReprov", - "RespCtrlReprov", - "", - sizeof(RespCtrlReprov), - 0, - resp_ctrl_reprov__field_descriptors, - resp_ctrl_reprov__field_indices_by_name, - 0, resp_ctrl_reprov__number_ranges, - (ProtobufCMessageInit) resp_ctrl_reprov__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor wi_fi_ctrl_payload__field_descriptors[6] = -{ - { - "msg", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WiFiCtrlPayload, msg), - &wi_fi_ctrl_msg_type__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "status", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WiFiCtrlPayload, status), - &status__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_ctrl_reset", - 11, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiCtrlPayload, payload_case), - offsetof(WiFiCtrlPayload, cmd_ctrl_reset), - &cmd_ctrl_reset__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_ctrl_reset", - 12, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiCtrlPayload, payload_case), - offsetof(WiFiCtrlPayload, resp_ctrl_reset), - &resp_ctrl_reset__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_ctrl_reprov", - 13, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiCtrlPayload, payload_case), - offsetof(WiFiCtrlPayload, cmd_ctrl_reprov), - &cmd_ctrl_reprov__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_ctrl_reprov", - 14, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiCtrlPayload, payload_case), - offsetof(WiFiCtrlPayload, resp_ctrl_reprov), - &resp_ctrl_reprov__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned wi_fi_ctrl_payload__field_indices_by_name[] = { - 4, /* field[4] = cmd_ctrl_reprov */ - 2, /* field[2] = cmd_ctrl_reset */ - 0, /* field[0] = msg */ - 5, /* field[5] = resp_ctrl_reprov */ - 3, /* field[3] = resp_ctrl_reset */ - 1, /* field[1] = status */ -}; -static const ProtobufCIntRange wi_fi_ctrl_payload__number_ranges[2 + 1] = -{ - { 1, 0 }, - { 11, 2 }, - { 0, 6 } -}; -const ProtobufCMessageDescriptor wi_fi_ctrl_payload__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "WiFiCtrlPayload", - "WiFiCtrlPayload", - "WiFiCtrlPayload", - "", - sizeof(WiFiCtrlPayload), - 6, - wi_fi_ctrl_payload__field_descriptors, - wi_fi_ctrl_payload__field_indices_by_name, - 2, wi_fi_ctrl_payload__number_ranges, - (ProtobufCMessageInit) wi_fi_ctrl_payload__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCEnumValue wi_fi_ctrl_msg_type__enum_values_by_number[5] = -{ - { "TypeCtrlReserved", "WI_FI_CTRL_MSG_TYPE__TypeCtrlReserved", 0 }, - { "TypeCmdCtrlReset", "WI_FI_CTRL_MSG_TYPE__TypeCmdCtrlReset", 1 }, - { "TypeRespCtrlReset", "WI_FI_CTRL_MSG_TYPE__TypeRespCtrlReset", 2 }, - { "TypeCmdCtrlReprov", "WI_FI_CTRL_MSG_TYPE__TypeCmdCtrlReprov", 3 }, - { "TypeRespCtrlReprov", "WI_FI_CTRL_MSG_TYPE__TypeRespCtrlReprov", 4 }, -}; -static const ProtobufCIntRange wi_fi_ctrl_msg_type__value_ranges[] = { -{0, 0},{0, 5} -}; -static const ProtobufCEnumValueIndex wi_fi_ctrl_msg_type__enum_values_by_name[5] = -{ - { "TypeCmdCtrlReprov", 3 }, - { "TypeCmdCtrlReset", 1 }, - { "TypeCtrlReserved", 0 }, - { "TypeRespCtrlReprov", 4 }, - { "TypeRespCtrlReset", 2 }, -}; -const ProtobufCEnumDescriptor wi_fi_ctrl_msg_type__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "WiFiCtrlMsgType", - "WiFiCtrlMsgType", - "WiFiCtrlMsgType", - "", - 5, - wi_fi_ctrl_msg_type__enum_values_by_number, - 5, - wi_fi_ctrl_msg_type__enum_values_by_name, - 1, - wi_fi_ctrl_msg_type__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; diff --git a/components/wifi_provisioning/proto-c/wifi_ctrl.pb-c.h b/components/wifi_provisioning/proto-c/wifi_ctrl.pb-c.h deleted file mode 100644 index 2291bf31c8f5..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_ctrl.pb-c.h +++ /dev/null @@ -1,230 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_ctrl.proto */ - -#ifndef PROTOBUF_C_wifi_5fctrl_2eproto__INCLUDED -#define PROTOBUF_C_wifi_5fctrl_2eproto__INCLUDED - -#include - -PROTOBUF_C__BEGIN_DECLS - -#if PROTOBUF_C_VERSION_NUMBER < 1003000 -# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. -#elif 1004001 < PROTOBUF_C_MIN_COMPILER_VERSION -# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. -#endif - -#include "constants.pb-c.h" - -typedef struct CmdCtrlReset CmdCtrlReset; -typedef struct RespCtrlReset RespCtrlReset; -typedef struct CmdCtrlReprov CmdCtrlReprov; -typedef struct RespCtrlReprov RespCtrlReprov; -typedef struct WiFiCtrlPayload WiFiCtrlPayload; - - -/* --- enums --- */ - -typedef enum _WiFiCtrlMsgType { - WI_FI_CTRL_MSG_TYPE__TypeCtrlReserved = 0, - WI_FI_CTRL_MSG_TYPE__TypeCmdCtrlReset = 1, - WI_FI_CTRL_MSG_TYPE__TypeRespCtrlReset = 2, - WI_FI_CTRL_MSG_TYPE__TypeCmdCtrlReprov = 3, - WI_FI_CTRL_MSG_TYPE__TypeRespCtrlReprov = 4 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WI_FI_CTRL_MSG_TYPE) -} WiFiCtrlMsgType; - -/* --- messages --- */ - -struct CmdCtrlReset -{ - ProtobufCMessage base; -}; -#define CMD_CTRL_RESET__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_ctrl_reset__descriptor) \ - } - - -struct RespCtrlReset -{ - ProtobufCMessage base; -}; -#define RESP_CTRL_RESET__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_ctrl_reset__descriptor) \ - } - - -struct CmdCtrlReprov -{ - ProtobufCMessage base; -}; -#define CMD_CTRL_REPROV__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_ctrl_reprov__descriptor) \ - } - - -struct RespCtrlReprov -{ - ProtobufCMessage base; -}; -#define RESP_CTRL_REPROV__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_ctrl_reprov__descriptor) \ - } - - -typedef enum { - WI_FI_CTRL_PAYLOAD__PAYLOAD__NOT_SET = 0, - WI_FI_CTRL_PAYLOAD__PAYLOAD_CMD_CTRL_RESET = 11, - WI_FI_CTRL_PAYLOAD__PAYLOAD_RESP_CTRL_RESET = 12, - WI_FI_CTRL_PAYLOAD__PAYLOAD_CMD_CTRL_REPROV = 13, - WI_FI_CTRL_PAYLOAD__PAYLOAD_RESP_CTRL_REPROV = 14 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WI_FI_CTRL_PAYLOAD__PAYLOAD__CASE) -} WiFiCtrlPayload__PayloadCase; - -struct WiFiCtrlPayload -{ - ProtobufCMessage base; - WiFiCtrlMsgType msg; - Status status; - WiFiCtrlPayload__PayloadCase payload_case; - union { - CmdCtrlReset *cmd_ctrl_reset; - RespCtrlReset *resp_ctrl_reset; - CmdCtrlReprov *cmd_ctrl_reprov; - RespCtrlReprov *resp_ctrl_reprov; - }; -}; -#define WI_FI_CTRL_PAYLOAD__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&wi_fi_ctrl_payload__descriptor) \ - , WI_FI_CTRL_MSG_TYPE__TypeCtrlReserved, STATUS__Success, WI_FI_CTRL_PAYLOAD__PAYLOAD__NOT_SET, {0} } - - -/* CmdCtrlReset methods */ -void cmd_ctrl_reset__init - (CmdCtrlReset *message); -size_t cmd_ctrl_reset__get_packed_size - (const CmdCtrlReset *message); -size_t cmd_ctrl_reset__pack - (const CmdCtrlReset *message, - uint8_t *out); -size_t cmd_ctrl_reset__pack_to_buffer - (const CmdCtrlReset *message, - ProtobufCBuffer *buffer); -CmdCtrlReset * - cmd_ctrl_reset__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_ctrl_reset__free_unpacked - (CmdCtrlReset *message, - ProtobufCAllocator *allocator); -/* RespCtrlReset methods */ -void resp_ctrl_reset__init - (RespCtrlReset *message); -size_t resp_ctrl_reset__get_packed_size - (const RespCtrlReset *message); -size_t resp_ctrl_reset__pack - (const RespCtrlReset *message, - uint8_t *out); -size_t resp_ctrl_reset__pack_to_buffer - (const RespCtrlReset *message, - ProtobufCBuffer *buffer); -RespCtrlReset * - resp_ctrl_reset__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_ctrl_reset__free_unpacked - (RespCtrlReset *message, - ProtobufCAllocator *allocator); -/* CmdCtrlReprov methods */ -void cmd_ctrl_reprov__init - (CmdCtrlReprov *message); -size_t cmd_ctrl_reprov__get_packed_size - (const CmdCtrlReprov *message); -size_t cmd_ctrl_reprov__pack - (const CmdCtrlReprov *message, - uint8_t *out); -size_t cmd_ctrl_reprov__pack_to_buffer - (const CmdCtrlReprov *message, - ProtobufCBuffer *buffer); -CmdCtrlReprov * - cmd_ctrl_reprov__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_ctrl_reprov__free_unpacked - (CmdCtrlReprov *message, - ProtobufCAllocator *allocator); -/* RespCtrlReprov methods */ -void resp_ctrl_reprov__init - (RespCtrlReprov *message); -size_t resp_ctrl_reprov__get_packed_size - (const RespCtrlReprov *message); -size_t resp_ctrl_reprov__pack - (const RespCtrlReprov *message, - uint8_t *out); -size_t resp_ctrl_reprov__pack_to_buffer - (const RespCtrlReprov *message, - ProtobufCBuffer *buffer); -RespCtrlReprov * - resp_ctrl_reprov__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_ctrl_reprov__free_unpacked - (RespCtrlReprov *message, - ProtobufCAllocator *allocator); -/* WiFiCtrlPayload methods */ -void wi_fi_ctrl_payload__init - (WiFiCtrlPayload *message); -size_t wi_fi_ctrl_payload__get_packed_size - (const WiFiCtrlPayload *message); -size_t wi_fi_ctrl_payload__pack - (const WiFiCtrlPayload *message, - uint8_t *out); -size_t wi_fi_ctrl_payload__pack_to_buffer - (const WiFiCtrlPayload *message, - ProtobufCBuffer *buffer); -WiFiCtrlPayload * - wi_fi_ctrl_payload__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void wi_fi_ctrl_payload__free_unpacked - (WiFiCtrlPayload *message, - ProtobufCAllocator *allocator); -/* --- per-message closures --- */ - -typedef void (*CmdCtrlReset_Closure) - (const CmdCtrlReset *message, - void *closure_data); -typedef void (*RespCtrlReset_Closure) - (const RespCtrlReset *message, - void *closure_data); -typedef void (*CmdCtrlReprov_Closure) - (const CmdCtrlReprov *message, - void *closure_data); -typedef void (*RespCtrlReprov_Closure) - (const RespCtrlReprov *message, - void *closure_data); -typedef void (*WiFiCtrlPayload_Closure) - (const WiFiCtrlPayload *message, - void *closure_data); - -/* --- services --- */ - - -/* --- descriptors --- */ - -extern const ProtobufCEnumDescriptor wi_fi_ctrl_msg_type__descriptor; -extern const ProtobufCMessageDescriptor cmd_ctrl_reset__descriptor; -extern const ProtobufCMessageDescriptor resp_ctrl_reset__descriptor; -extern const ProtobufCMessageDescriptor cmd_ctrl_reprov__descriptor; -extern const ProtobufCMessageDescriptor resp_ctrl_reprov__descriptor; -extern const ProtobufCMessageDescriptor wi_fi_ctrl_payload__descriptor; - -PROTOBUF_C__END_DECLS - - -#endif /* PROTOBUF_C_wifi_5fctrl_2eproto__INCLUDED */ diff --git a/components/wifi_provisioning/proto-c/wifi_scan.pb-c.c b/components/wifi_provisioning/proto-c/wifi_scan.pb-c.c deleted file mode 100644 index 4cf5b5dc3b1f..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_scan.pb-c.c +++ /dev/null @@ -1,878 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_scan.proto */ - -/* Do not generate deprecated warnings for self */ -#ifndef PROTOBUF_C__NO_DEPRECATED -#define PROTOBUF_C__NO_DEPRECATED -#endif - -#include "wifi_scan.pb-c.h" -void cmd_scan_start__init - (CmdScanStart *message) -{ - static const CmdScanStart init_value = CMD_SCAN_START__INIT; - *message = init_value; -} -size_t cmd_scan_start__get_packed_size - (const CmdScanStart *message) -{ - assert(message->base.descriptor == &cmd_scan_start__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_scan_start__pack - (const CmdScanStart *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_scan_start__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_scan_start__pack_to_buffer - (const CmdScanStart *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_scan_start__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdScanStart * - cmd_scan_start__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdScanStart *) - protobuf_c_message_unpack (&cmd_scan_start__descriptor, - allocator, len, data); -} -void cmd_scan_start__free_unpacked - (CmdScanStart *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_scan_start__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_scan_start__init - (RespScanStart *message) -{ - static const RespScanStart init_value = RESP_SCAN_START__INIT; - *message = init_value; -} -size_t resp_scan_start__get_packed_size - (const RespScanStart *message) -{ - assert(message->base.descriptor == &resp_scan_start__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_scan_start__pack - (const RespScanStart *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_scan_start__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_scan_start__pack_to_buffer - (const RespScanStart *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_scan_start__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespScanStart * - resp_scan_start__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespScanStart *) - protobuf_c_message_unpack (&resp_scan_start__descriptor, - allocator, len, data); -} -void resp_scan_start__free_unpacked - (RespScanStart *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_scan_start__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void cmd_scan_status__init - (CmdScanStatus *message) -{ - static const CmdScanStatus init_value = CMD_SCAN_STATUS__INIT; - *message = init_value; -} -size_t cmd_scan_status__get_packed_size - (const CmdScanStatus *message) -{ - assert(message->base.descriptor == &cmd_scan_status__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_scan_status__pack - (const CmdScanStatus *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_scan_status__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_scan_status__pack_to_buffer - (const CmdScanStatus *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_scan_status__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdScanStatus * - cmd_scan_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdScanStatus *) - protobuf_c_message_unpack (&cmd_scan_status__descriptor, - allocator, len, data); -} -void cmd_scan_status__free_unpacked - (CmdScanStatus *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_scan_status__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_scan_status__init - (RespScanStatus *message) -{ - static const RespScanStatus init_value = RESP_SCAN_STATUS__INIT; - *message = init_value; -} -size_t resp_scan_status__get_packed_size - (const RespScanStatus *message) -{ - assert(message->base.descriptor == &resp_scan_status__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_scan_status__pack - (const RespScanStatus *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_scan_status__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_scan_status__pack_to_buffer - (const RespScanStatus *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_scan_status__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespScanStatus * - resp_scan_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespScanStatus *) - protobuf_c_message_unpack (&resp_scan_status__descriptor, - allocator, len, data); -} -void resp_scan_status__free_unpacked - (RespScanStatus *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_scan_status__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void cmd_scan_result__init - (CmdScanResult *message) -{ - static const CmdScanResult init_value = CMD_SCAN_RESULT__INIT; - *message = init_value; -} -size_t cmd_scan_result__get_packed_size - (const CmdScanResult *message) -{ - assert(message->base.descriptor == &cmd_scan_result__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t cmd_scan_result__pack - (const CmdScanResult *message, - uint8_t *out) -{ - assert(message->base.descriptor == &cmd_scan_result__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t cmd_scan_result__pack_to_buffer - (const CmdScanResult *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &cmd_scan_result__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -CmdScanResult * - cmd_scan_result__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (CmdScanResult *) - protobuf_c_message_unpack (&cmd_scan_result__descriptor, - allocator, len, data); -} -void cmd_scan_result__free_unpacked - (CmdScanResult *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &cmd_scan_result__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void wi_fi_scan_result__init - (WiFiScanResult *message) -{ - static const WiFiScanResult init_value = WI_FI_SCAN_RESULT__INIT; - *message = init_value; -} -size_t wi_fi_scan_result__get_packed_size - (const WiFiScanResult *message) -{ - assert(message->base.descriptor == &wi_fi_scan_result__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t wi_fi_scan_result__pack - (const WiFiScanResult *message, - uint8_t *out) -{ - assert(message->base.descriptor == &wi_fi_scan_result__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t wi_fi_scan_result__pack_to_buffer - (const WiFiScanResult *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &wi_fi_scan_result__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -WiFiScanResult * - wi_fi_scan_result__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (WiFiScanResult *) - protobuf_c_message_unpack (&wi_fi_scan_result__descriptor, - allocator, len, data); -} -void wi_fi_scan_result__free_unpacked - (WiFiScanResult *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &wi_fi_scan_result__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void resp_scan_result__init - (RespScanResult *message) -{ - static const RespScanResult init_value = RESP_SCAN_RESULT__INIT; - *message = init_value; -} -size_t resp_scan_result__get_packed_size - (const RespScanResult *message) -{ - assert(message->base.descriptor == &resp_scan_result__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t resp_scan_result__pack - (const RespScanResult *message, - uint8_t *out) -{ - assert(message->base.descriptor == &resp_scan_result__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t resp_scan_result__pack_to_buffer - (const RespScanResult *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &resp_scan_result__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -RespScanResult * - resp_scan_result__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (RespScanResult *) - protobuf_c_message_unpack (&resp_scan_result__descriptor, - allocator, len, data); -} -void resp_scan_result__free_unpacked - (RespScanResult *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &resp_scan_result__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -void wi_fi_scan_payload__init - (WiFiScanPayload *message) -{ - static const WiFiScanPayload init_value = WI_FI_SCAN_PAYLOAD__INIT; - *message = init_value; -} -size_t wi_fi_scan_payload__get_packed_size - (const WiFiScanPayload *message) -{ - assert(message->base.descriptor == &wi_fi_scan_payload__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); -} -size_t wi_fi_scan_payload__pack - (const WiFiScanPayload *message, - uint8_t *out) -{ - assert(message->base.descriptor == &wi_fi_scan_payload__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); -} -size_t wi_fi_scan_payload__pack_to_buffer - (const WiFiScanPayload *message, - ProtobufCBuffer *buffer) -{ - assert(message->base.descriptor == &wi_fi_scan_payload__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); -} -WiFiScanPayload * - wi_fi_scan_payload__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) -{ - return (WiFiScanPayload *) - protobuf_c_message_unpack (&wi_fi_scan_payload__descriptor, - allocator, len, data); -} -void wi_fi_scan_payload__free_unpacked - (WiFiScanPayload *message, - ProtobufCAllocator *allocator) -{ - if(!message) - return; - assert(message->base.descriptor == &wi_fi_scan_payload__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); -} -static const ProtobufCFieldDescriptor cmd_scan_start__field_descriptors[4] = -{ - { - "blocking", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BOOL, - 0, /* quantifier_offset */ - offsetof(CmdScanStart, blocking), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "passive", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BOOL, - 0, /* quantifier_offset */ - offsetof(CmdScanStart, passive), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "group_channels", - 3, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_UINT32, - 0, /* quantifier_offset */ - offsetof(CmdScanStart, group_channels), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "period_ms", - 4, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_UINT32, - 0, /* quantifier_offset */ - offsetof(CmdScanStart, period_ms), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned cmd_scan_start__field_indices_by_name[] = { - 0, /* field[0] = blocking */ - 2, /* field[2] = group_channels */ - 1, /* field[1] = passive */ - 3, /* field[3] = period_ms */ -}; -static const ProtobufCIntRange cmd_scan_start__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 4 } -}; -const ProtobufCMessageDescriptor cmd_scan_start__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdScanStart", - "CmdScanStart", - "CmdScanStart", - "", - sizeof(CmdScanStart), - 4, - cmd_scan_start__field_descriptors, - cmd_scan_start__field_indices_by_name, - 1, cmd_scan_start__number_ranges, - (ProtobufCMessageInit) cmd_scan_start__init, - NULL,NULL,NULL /* reserved[123] */ -}; -#define resp_scan_start__field_descriptors NULL -#define resp_scan_start__field_indices_by_name NULL -#define resp_scan_start__number_ranges NULL -const ProtobufCMessageDescriptor resp_scan_start__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespScanStart", - "RespScanStart", - "RespScanStart", - "", - sizeof(RespScanStart), - 0, - resp_scan_start__field_descriptors, - resp_scan_start__field_indices_by_name, - 0, resp_scan_start__number_ranges, - (ProtobufCMessageInit) resp_scan_start__init, - NULL,NULL,NULL /* reserved[123] */ -}; -#define cmd_scan_status__field_descriptors NULL -#define cmd_scan_status__field_indices_by_name NULL -#define cmd_scan_status__number_ranges NULL -const ProtobufCMessageDescriptor cmd_scan_status__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdScanStatus", - "CmdScanStatus", - "CmdScanStatus", - "", - sizeof(CmdScanStatus), - 0, - cmd_scan_status__field_descriptors, - cmd_scan_status__field_indices_by_name, - 0, cmd_scan_status__number_ranges, - (ProtobufCMessageInit) cmd_scan_status__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor resp_scan_status__field_descriptors[2] = -{ - { - "scan_finished", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BOOL, - 0, /* quantifier_offset */ - offsetof(RespScanStatus, scan_finished), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "result_count", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_UINT32, - 0, /* quantifier_offset */ - offsetof(RespScanStatus, result_count), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned resp_scan_status__field_indices_by_name[] = { - 1, /* field[1] = result_count */ - 0, /* field[0] = scan_finished */ -}; -static const ProtobufCIntRange resp_scan_status__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor resp_scan_status__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespScanStatus", - "RespScanStatus", - "RespScanStatus", - "", - sizeof(RespScanStatus), - 2, - resp_scan_status__field_descriptors, - resp_scan_status__field_indices_by_name, - 1, resp_scan_status__number_ranges, - (ProtobufCMessageInit) resp_scan_status__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor cmd_scan_result__field_descriptors[2] = -{ - { - "start_index", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_UINT32, - 0, /* quantifier_offset */ - offsetof(CmdScanResult, start_index), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "count", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_UINT32, - 0, /* quantifier_offset */ - offsetof(CmdScanResult, count), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned cmd_scan_result__field_indices_by_name[] = { - 1, /* field[1] = count */ - 0, /* field[0] = start_index */ -}; -static const ProtobufCIntRange cmd_scan_result__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor cmd_scan_result__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "CmdScanResult", - "CmdScanResult", - "CmdScanResult", - "", - sizeof(CmdScanResult), - 2, - cmd_scan_result__field_descriptors, - cmd_scan_result__field_indices_by_name, - 1, cmd_scan_result__number_ranges, - (ProtobufCMessageInit) cmd_scan_result__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor wi_fi_scan_result__field_descriptors[5] = -{ - { - "ssid", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(WiFiScanResult, ssid), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "channel", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_UINT32, - 0, /* quantifier_offset */ - offsetof(WiFiScanResult, channel), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "rssi", - 3, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_INT32, - 0, /* quantifier_offset */ - offsetof(WiFiScanResult, rssi), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "bssid", - 4, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_BYTES, - 0, /* quantifier_offset */ - offsetof(WiFiScanResult, bssid), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "auth", - 5, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WiFiScanResult, auth), - &wifi_auth_mode__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned wi_fi_scan_result__field_indices_by_name[] = { - 4, /* field[4] = auth */ - 3, /* field[3] = bssid */ - 1, /* field[1] = channel */ - 2, /* field[2] = rssi */ - 0, /* field[0] = ssid */ -}; -static const ProtobufCIntRange wi_fi_scan_result__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 5 } -}; -const ProtobufCMessageDescriptor wi_fi_scan_result__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "WiFiScanResult", - "WiFiScanResult", - "WiFiScanResult", - "", - sizeof(WiFiScanResult), - 5, - wi_fi_scan_result__field_descriptors, - wi_fi_scan_result__field_indices_by_name, - 1, wi_fi_scan_result__number_ranges, - (ProtobufCMessageInit) wi_fi_scan_result__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor resp_scan_result__field_descriptors[1] = -{ - { - "entries", - 1, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(RespScanResult, n_entries), - offsetof(RespScanResult, entries), - &wi_fi_scan_result__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned resp_scan_result__field_indices_by_name[] = { - 0, /* field[0] = entries */ -}; -static const ProtobufCIntRange resp_scan_result__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 1 } -}; -const ProtobufCMessageDescriptor resp_scan_result__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "RespScanResult", - "RespScanResult", - "RespScanResult", - "", - sizeof(RespScanResult), - 1, - resp_scan_result__field_descriptors, - resp_scan_result__field_indices_by_name, - 1, resp_scan_result__number_ranges, - (ProtobufCMessageInit) resp_scan_result__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor wi_fi_scan_payload__field_descriptors[8] = -{ - { - "msg", - 1, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WiFiScanPayload, msg), - &wi_fi_scan_msg_type__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "status", - 2, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_ENUM, - 0, /* quantifier_offset */ - offsetof(WiFiScanPayload, status), - &status__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_scan_start", - 10, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiScanPayload, payload_case), - offsetof(WiFiScanPayload, cmd_scan_start), - &cmd_scan_start__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_scan_start", - 11, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiScanPayload, payload_case), - offsetof(WiFiScanPayload, resp_scan_start), - &resp_scan_start__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_scan_status", - 12, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiScanPayload, payload_case), - offsetof(WiFiScanPayload, cmd_scan_status), - &cmd_scan_status__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_scan_status", - 13, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiScanPayload, payload_case), - offsetof(WiFiScanPayload, resp_scan_status), - &resp_scan_status__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "cmd_scan_result", - 14, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiScanPayload, payload_case), - offsetof(WiFiScanPayload, cmd_scan_result), - &cmd_scan_result__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "resp_scan_result", - 15, - PROTOBUF_C_LABEL_NONE, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(WiFiScanPayload, payload_case), - offsetof(WiFiScanPayload, resp_scan_result), - &resp_scan_result__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned wi_fi_scan_payload__field_indices_by_name[] = { - 6, /* field[6] = cmd_scan_result */ - 2, /* field[2] = cmd_scan_start */ - 4, /* field[4] = cmd_scan_status */ - 0, /* field[0] = msg */ - 7, /* field[7] = resp_scan_result */ - 3, /* field[3] = resp_scan_start */ - 5, /* field[5] = resp_scan_status */ - 1, /* field[1] = status */ -}; -static const ProtobufCIntRange wi_fi_scan_payload__number_ranges[2 + 1] = -{ - { 1, 0 }, - { 10, 2 }, - { 0, 8 } -}; -const ProtobufCMessageDescriptor wi_fi_scan_payload__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "WiFiScanPayload", - "WiFiScanPayload", - "WiFiScanPayload", - "", - sizeof(WiFiScanPayload), - 8, - wi_fi_scan_payload__field_descriptors, - wi_fi_scan_payload__field_indices_by_name, - 2, wi_fi_scan_payload__number_ranges, - (ProtobufCMessageInit) wi_fi_scan_payload__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCEnumValue wi_fi_scan_msg_type__enum_values_by_number[6] = -{ - { "TypeCmdScanStart", "WI_FI_SCAN_MSG_TYPE__TypeCmdScanStart", 0 }, - { "TypeRespScanStart", "WI_FI_SCAN_MSG_TYPE__TypeRespScanStart", 1 }, - { "TypeCmdScanStatus", "WI_FI_SCAN_MSG_TYPE__TypeCmdScanStatus", 2 }, - { "TypeRespScanStatus", "WI_FI_SCAN_MSG_TYPE__TypeRespScanStatus", 3 }, - { "TypeCmdScanResult", "WI_FI_SCAN_MSG_TYPE__TypeCmdScanResult", 4 }, - { "TypeRespScanResult", "WI_FI_SCAN_MSG_TYPE__TypeRespScanResult", 5 }, -}; -static const ProtobufCIntRange wi_fi_scan_msg_type__value_ranges[] = { -{0, 0},{0, 6} -}; -static const ProtobufCEnumValueIndex wi_fi_scan_msg_type__enum_values_by_name[6] = -{ - { "TypeCmdScanResult", 4 }, - { "TypeCmdScanStart", 0 }, - { "TypeCmdScanStatus", 2 }, - { "TypeRespScanResult", 5 }, - { "TypeRespScanStart", 1 }, - { "TypeRespScanStatus", 3 }, -}; -const ProtobufCEnumDescriptor wi_fi_scan_msg_type__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "WiFiScanMsgType", - "WiFiScanMsgType", - "WiFiScanMsgType", - "", - 6, - wi_fi_scan_msg_type__enum_values_by_number, - 6, - wi_fi_scan_msg_type__enum_values_by_name, - 1, - wi_fi_scan_msg_type__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; diff --git a/components/wifi_provisioning/proto-c/wifi_scan.pb-c.h b/components/wifi_provisioning/proto-c/wifi_scan.pb-c.h deleted file mode 100644 index dc3975590da5..000000000000 --- a/components/wifi_provisioning/proto-c/wifi_scan.pb-c.h +++ /dev/null @@ -1,350 +0,0 @@ -/* Generated by the protocol buffer compiler. DO NOT EDIT! */ -/* Generated from: wifi_scan.proto */ - -#ifndef PROTOBUF_C_wifi_5fscan_2eproto__INCLUDED -#define PROTOBUF_C_wifi_5fscan_2eproto__INCLUDED - -#include - -PROTOBUF_C__BEGIN_DECLS - -#if PROTOBUF_C_VERSION_NUMBER < 1003000 -# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. -#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION -# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. -#endif - -#include "constants.pb-c.h" -#include "wifi_constants.pb-c.h" - -typedef struct CmdScanStart CmdScanStart; -typedef struct RespScanStart RespScanStart; -typedef struct CmdScanStatus CmdScanStatus; -typedef struct RespScanStatus RespScanStatus; -typedef struct CmdScanResult CmdScanResult; -typedef struct WiFiScanResult WiFiScanResult; -typedef struct RespScanResult RespScanResult; -typedef struct WiFiScanPayload WiFiScanPayload; - - -/* --- enums --- */ - -typedef enum _WiFiScanMsgType { - WI_FI_SCAN_MSG_TYPE__TypeCmdScanStart = 0, - WI_FI_SCAN_MSG_TYPE__TypeRespScanStart = 1, - WI_FI_SCAN_MSG_TYPE__TypeCmdScanStatus = 2, - WI_FI_SCAN_MSG_TYPE__TypeRespScanStatus = 3, - WI_FI_SCAN_MSG_TYPE__TypeCmdScanResult = 4, - WI_FI_SCAN_MSG_TYPE__TypeRespScanResult = 5 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WI_FI_SCAN_MSG_TYPE) -} WiFiScanMsgType; - -/* --- messages --- */ - -struct CmdScanStart -{ - ProtobufCMessage base; - protobuf_c_boolean blocking; - protobuf_c_boolean passive; - uint32_t group_channels; - uint32_t period_ms; -}; -#define CMD_SCAN_START__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_scan_start__descriptor) \ - , 0, 0, 0, 0 } - - -struct RespScanStart -{ - ProtobufCMessage base; -}; -#define RESP_SCAN_START__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_scan_start__descriptor) \ - } - - -struct CmdScanStatus -{ - ProtobufCMessage base; -}; -#define CMD_SCAN_STATUS__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_scan_status__descriptor) \ - } - - -struct RespScanStatus -{ - ProtobufCMessage base; - protobuf_c_boolean scan_finished; - uint32_t result_count; -}; -#define RESP_SCAN_STATUS__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_scan_status__descriptor) \ - , 0, 0 } - - -struct CmdScanResult -{ - ProtobufCMessage base; - uint32_t start_index; - uint32_t count; -}; -#define CMD_SCAN_RESULT__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&cmd_scan_result__descriptor) \ - , 0, 0 } - - -struct WiFiScanResult -{ - ProtobufCMessage base; - ProtobufCBinaryData ssid; - uint32_t channel; - int32_t rssi; - ProtobufCBinaryData bssid; - WifiAuthMode auth; -}; -#define WI_FI_SCAN_RESULT__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&wi_fi_scan_result__descriptor) \ - , {0,NULL}, 0, 0, {0,NULL}, WIFI_AUTH_MODE__Open } - - -struct RespScanResult -{ - ProtobufCMessage base; - size_t n_entries; - WiFiScanResult **entries; -}; -#define RESP_SCAN_RESULT__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&resp_scan_result__descriptor) \ - , 0,NULL } - - -typedef enum { - WI_FI_SCAN_PAYLOAD__PAYLOAD__NOT_SET = 0, - WI_FI_SCAN_PAYLOAD__PAYLOAD_CMD_SCAN_START = 10, - WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_START = 11, - WI_FI_SCAN_PAYLOAD__PAYLOAD_CMD_SCAN_STATUS = 12, - WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_STATUS = 13, - WI_FI_SCAN_PAYLOAD__PAYLOAD_CMD_SCAN_RESULT = 14, - WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_RESULT = 15 - PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(WI_FI_SCAN_PAYLOAD__PAYLOAD__CASE) -} WiFiScanPayload__PayloadCase; - -struct WiFiScanPayload -{ - ProtobufCMessage base; - WiFiScanMsgType msg; - Status status; - WiFiScanPayload__PayloadCase payload_case; - union { - CmdScanStart *cmd_scan_start; - RespScanStart *resp_scan_start; - CmdScanStatus *cmd_scan_status; - RespScanStatus *resp_scan_status; - CmdScanResult *cmd_scan_result; - RespScanResult *resp_scan_result; - }; -}; -#define WI_FI_SCAN_PAYLOAD__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&wi_fi_scan_payload__descriptor) \ - , WI_FI_SCAN_MSG_TYPE__TypeCmdScanStart, STATUS__Success, WI_FI_SCAN_PAYLOAD__PAYLOAD__NOT_SET, {0} } - - -/* CmdScanStart methods */ -void cmd_scan_start__init - (CmdScanStart *message); -size_t cmd_scan_start__get_packed_size - (const CmdScanStart *message); -size_t cmd_scan_start__pack - (const CmdScanStart *message, - uint8_t *out); -size_t cmd_scan_start__pack_to_buffer - (const CmdScanStart *message, - ProtobufCBuffer *buffer); -CmdScanStart * - cmd_scan_start__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_scan_start__free_unpacked - (CmdScanStart *message, - ProtobufCAllocator *allocator); -/* RespScanStart methods */ -void resp_scan_start__init - (RespScanStart *message); -size_t resp_scan_start__get_packed_size - (const RespScanStart *message); -size_t resp_scan_start__pack - (const RespScanStart *message, - uint8_t *out); -size_t resp_scan_start__pack_to_buffer - (const RespScanStart *message, - ProtobufCBuffer *buffer); -RespScanStart * - resp_scan_start__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_scan_start__free_unpacked - (RespScanStart *message, - ProtobufCAllocator *allocator); -/* CmdScanStatus methods */ -void cmd_scan_status__init - (CmdScanStatus *message); -size_t cmd_scan_status__get_packed_size - (const CmdScanStatus *message); -size_t cmd_scan_status__pack - (const CmdScanStatus *message, - uint8_t *out); -size_t cmd_scan_status__pack_to_buffer - (const CmdScanStatus *message, - ProtobufCBuffer *buffer); -CmdScanStatus * - cmd_scan_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_scan_status__free_unpacked - (CmdScanStatus *message, - ProtobufCAllocator *allocator); -/* RespScanStatus methods */ -void resp_scan_status__init - (RespScanStatus *message); -size_t resp_scan_status__get_packed_size - (const RespScanStatus *message); -size_t resp_scan_status__pack - (const RespScanStatus *message, - uint8_t *out); -size_t resp_scan_status__pack_to_buffer - (const RespScanStatus *message, - ProtobufCBuffer *buffer); -RespScanStatus * - resp_scan_status__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_scan_status__free_unpacked - (RespScanStatus *message, - ProtobufCAllocator *allocator); -/* CmdScanResult methods */ -void cmd_scan_result__init - (CmdScanResult *message); -size_t cmd_scan_result__get_packed_size - (const CmdScanResult *message); -size_t cmd_scan_result__pack - (const CmdScanResult *message, - uint8_t *out); -size_t cmd_scan_result__pack_to_buffer - (const CmdScanResult *message, - ProtobufCBuffer *buffer); -CmdScanResult * - cmd_scan_result__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void cmd_scan_result__free_unpacked - (CmdScanResult *message, - ProtobufCAllocator *allocator); -/* WiFiScanResult methods */ -void wi_fi_scan_result__init - (WiFiScanResult *message); -size_t wi_fi_scan_result__get_packed_size - (const WiFiScanResult *message); -size_t wi_fi_scan_result__pack - (const WiFiScanResult *message, - uint8_t *out); -size_t wi_fi_scan_result__pack_to_buffer - (const WiFiScanResult *message, - ProtobufCBuffer *buffer); -WiFiScanResult * - wi_fi_scan_result__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void wi_fi_scan_result__free_unpacked - (WiFiScanResult *message, - ProtobufCAllocator *allocator); -/* RespScanResult methods */ -void resp_scan_result__init - (RespScanResult *message); -size_t resp_scan_result__get_packed_size - (const RespScanResult *message); -size_t resp_scan_result__pack - (const RespScanResult *message, - uint8_t *out); -size_t resp_scan_result__pack_to_buffer - (const RespScanResult *message, - ProtobufCBuffer *buffer); -RespScanResult * - resp_scan_result__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void resp_scan_result__free_unpacked - (RespScanResult *message, - ProtobufCAllocator *allocator); -/* WiFiScanPayload methods */ -void wi_fi_scan_payload__init - (WiFiScanPayload *message); -size_t wi_fi_scan_payload__get_packed_size - (const WiFiScanPayload *message); -size_t wi_fi_scan_payload__pack - (const WiFiScanPayload *message, - uint8_t *out); -size_t wi_fi_scan_payload__pack_to_buffer - (const WiFiScanPayload *message, - ProtobufCBuffer *buffer); -WiFiScanPayload * - wi_fi_scan_payload__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data); -void wi_fi_scan_payload__free_unpacked - (WiFiScanPayload *message, - ProtobufCAllocator *allocator); -/* --- per-message closures --- */ - -typedef void (*CmdScanStart_Closure) - (const CmdScanStart *message, - void *closure_data); -typedef void (*RespScanStart_Closure) - (const RespScanStart *message, - void *closure_data); -typedef void (*CmdScanStatus_Closure) - (const CmdScanStatus *message, - void *closure_data); -typedef void (*RespScanStatus_Closure) - (const RespScanStatus *message, - void *closure_data); -typedef void (*CmdScanResult_Closure) - (const CmdScanResult *message, - void *closure_data); -typedef void (*WiFiScanResult_Closure) - (const WiFiScanResult *message, - void *closure_data); -typedef void (*RespScanResult_Closure) - (const RespScanResult *message, - void *closure_data); -typedef void (*WiFiScanPayload_Closure) - (const WiFiScanPayload *message, - void *closure_data); - -/* --- services --- */ - - -/* --- descriptors --- */ - -extern const ProtobufCEnumDescriptor wi_fi_scan_msg_type__descriptor; -extern const ProtobufCMessageDescriptor cmd_scan_start__descriptor; -extern const ProtobufCMessageDescriptor resp_scan_start__descriptor; -extern const ProtobufCMessageDescriptor cmd_scan_status__descriptor; -extern const ProtobufCMessageDescriptor resp_scan_status__descriptor; -extern const ProtobufCMessageDescriptor cmd_scan_result__descriptor; -extern const ProtobufCMessageDescriptor wi_fi_scan_result__descriptor; -extern const ProtobufCMessageDescriptor resp_scan_result__descriptor; -extern const ProtobufCMessageDescriptor wi_fi_scan_payload__descriptor; - -PROTOBUF_C__END_DECLS - - -#endif /* PROTOBUF_C_wifi_5fscan_2eproto__INCLUDED */ diff --git a/components/wifi_provisioning/proto/CMakeLists.txt b/components/wifi_provisioning/proto/CMakeLists.txt deleted file mode 100644 index 08e6980b5447..000000000000 --- a/components/wifi_provisioning/proto/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -set(PROTO_COMPILER "protoc") -set(PROTO_C_COMPILER "protoc-c") -set(C_OUT_PATH "${CMAKE_CURRENT_LIST_DIR}/../proto-c") -set(PY_OUT_PATH "${CMAKE_CURRENT_LIST_DIR}/../python") -set(PROTOCOMM_INCL_PATH "${CMAKE_CURRENT_LIST_DIR}/../../protocomm/proto") - -set(PROTO_SRCS "wifi_constants.proto" - "wifi_config.proto" - "wifi_scan.proto") - -add_custom_target(c_proto - COMMAND ${PROTO_C_COMPILER} --c_out=${C_OUT_PATH} -I . -I ${PROTOCOMM_INCL_PATH} ${PROTO_SRCS} - VERBATIM - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - ) - -add_custom_target(python_proto - COMMAND ${PROTO_COMPILER} --python_out=${PY_OUT_PATH} -I . -I ${PROTOCOMM_INCL_PATH} ${PROTO_SRCS} - VERBATIM - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - ) - -add_custom_target(proto ALL - DEPENDS c_proto python_proto - VERBATIM - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - ) diff --git a/components/wifi_provisioning/proto/README.md b/components/wifi_provisioning/proto/README.md deleted file mode 100644 index 68f9be20583a..000000000000 --- a/components/wifi_provisioning/proto/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Protobuf files for defining Wi-Fi provisioning packet structures - -`wifi_provisioning` uses Google Protobuf for language, transport and architecture agnostic protocol communication. These proto files define the protocomm packet structure, separated across multiple files: -* wifi_contants.proto - Defines the various enums for indicating state of Wi-Fi (connected / disconnect / connecting), diconnect reasons, auth modes, etc. -* wifi_config.proto - Defines Wi-Fi configuration structures and commands for setting credentials (SSID, passphrase, BSSID), applying credentials and getting connection state. -* wifi_scan.proto - Defines Wi-Fi scan commands and result structures - -Note : These proto files are not automatically compiled during the build process. - -# Compilation - -Compilation requires protoc (Protobuf Compiler) and protoc-c (Protobuf C Compiler) installed. Since the generated files are to remain the same, as long as the proto files are not modified, therefore the generated files are already available under `components/wifi_provisioning/proto-c` and `components/wifi_provisioning/python` directories, and thus running cmake / make (and installing the Protobuf compilers) is optional. - -If using `cmake` follow the below steps. If using `make`, jump to Step 2 directly. - -## Step 1 (Only for cmake) - -When using cmake, first create a build directory and call cmake from inside: - -``` -mkdir build -cd build -cmake .. -``` - -## Step 2 - -Simply run `make` to generate the respective C and Python files. The newly created files will overwrite those under `components/wifi_provisioning/proto-c` and `components/wifi_provisioning/python` diff --git a/components/wifi_provisioning/proto/makefile b/components/wifi_provisioning/proto/makefile deleted file mode 100644 index 585e42267bab..000000000000 --- a/components/wifi_provisioning/proto/makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: c_proto python_proto - -c_proto: *.proto - @protoc-c --c_out=../proto-c/ -I . -I ../../protocomm/proto/ *.proto - -python_proto: *.proto - @protoc --python_out=../python/ -I . -I ../../protocomm/proto/ *.proto diff --git a/components/wifi_provisioning/proto/wifi_config.proto b/components/wifi_provisioning/proto/wifi_config.proto deleted file mode 100644 index e273dc8e552c..000000000000 --- a/components/wifi_provisioning/proto/wifi_config.proto +++ /dev/null @@ -1,57 +0,0 @@ -syntax = "proto3"; - -import "constants.proto"; -import "wifi_constants.proto"; - -message CmdGetStatus { - -} - -message RespGetStatus { - Status status = 1; - WifiStationState sta_state = 2; - oneof state { - WifiConnectFailedReason fail_reason = 10; - WifiConnectedState connected = 11; - } -} - -message CmdSetConfig { - bytes ssid = 1; - bytes passphrase = 2; - bytes bssid = 3; - int32 channel = 4; -} - -message RespSetConfig { - Status status = 1; -} - -message CmdApplyConfig { - -} - -message RespApplyConfig { - Status status = 1; -} - -enum WiFiConfigMsgType { - TypeCmdGetStatus = 0; - TypeRespGetStatus = 1; - TypeCmdSetConfig = 2; - TypeRespSetConfig = 3; - TypeCmdApplyConfig = 4; - TypeRespApplyConfig = 5; -} - -message WiFiConfigPayload { - WiFiConfigMsgType msg = 1; - oneof payload { - CmdGetStatus cmd_get_status = 10; - RespGetStatus resp_get_status = 11; - CmdSetConfig cmd_set_config = 12; - RespSetConfig resp_set_config = 13; - CmdApplyConfig cmd_apply_config = 14; - RespApplyConfig resp_apply_config = 15; - } -} diff --git a/components/wifi_provisioning/proto/wifi_constants.proto b/components/wifi_provisioning/proto/wifi_constants.proto deleted file mode 100644 index 8134b2ed7013..000000000000 --- a/components/wifi_provisioning/proto/wifi_constants.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -enum WifiStationState { - Connected = 0; - Connecting = 1; - Disconnected = 2; - ConnectionFailed = 3; -} - -enum WifiConnectFailedReason { - AuthError = 0; - NetworkNotFound = 1; -} - -enum WifiAuthMode { - Open = 0; - WEP = 1; - WPA_PSK = 2; - WPA2_PSK = 3; - WPA_WPA2_PSK = 4; - WPA2_ENTERPRISE = 5; - WPA3_PSK = 6; - WPA2_WPA3_PSK = 7; -} - -message WifiConnectedState { - string ip4_addr = 1; - WifiAuthMode auth_mode = 2; - bytes ssid = 3; - bytes bssid = 4; - int32 channel = 5; -} diff --git a/components/wifi_provisioning/proto/wifi_ctrl.proto b/components/wifi_provisioning/proto/wifi_ctrl.proto deleted file mode 100644 index a2f8c7e253a6..000000000000 --- a/components/wifi_provisioning/proto/wifi_ctrl.proto +++ /dev/null @@ -1,38 +0,0 @@ -syntax = "proto3"; - -import "constants.proto"; - -message CmdCtrlReset { - -} - -message RespCtrlReset { - -} - -message CmdCtrlReprov { - -} - -message RespCtrlReprov{ - -} - -enum WiFiCtrlMsgType { - TypeCtrlReserved = 0; - TypeCmdCtrlReset = 1; - TypeRespCtrlReset = 2; - TypeCmdCtrlReprov = 3; - TypeRespCtrlReprov = 4; -} - -message WiFiCtrlPayload { - WiFiCtrlMsgType msg = 1; - Status status = 2; - oneof payload { - CmdCtrlReset cmd_ctrl_reset = 11; - RespCtrlReset resp_ctrl_reset = 12; - CmdCtrlReprov cmd_ctrl_reprov = 13; - RespCtrlReprov resp_ctrl_reprov = 14; - } -} diff --git a/components/wifi_provisioning/proto/wifi_scan.proto b/components/wifi_provisioning/proto/wifi_scan.proto deleted file mode 100644 index ea240f20f72e..000000000000 --- a/components/wifi_provisioning/proto/wifi_scan.proto +++ /dev/null @@ -1,63 +0,0 @@ -syntax = "proto3"; - -import "constants.proto"; -import "wifi_constants.proto"; - -message CmdScanStart { - bool blocking = 1; - bool passive = 2; - uint32 group_channels = 3; - uint32 period_ms = 4; -} - -message RespScanStart { - -} - -message CmdScanStatus { - -} - -message RespScanStatus { - bool scan_finished = 1; - uint32 result_count = 2; -} - -message CmdScanResult { - uint32 start_index = 1; - uint32 count = 2; -} - -message WiFiScanResult { - bytes ssid = 1; - uint32 channel = 2; - int32 rssi = 3; - bytes bssid = 4; - WifiAuthMode auth = 5; -} - -message RespScanResult { - repeated WiFiScanResult entries = 1; -} - -enum WiFiScanMsgType { - TypeCmdScanStart = 0; - TypeRespScanStart = 1; - TypeCmdScanStatus = 2; - TypeRespScanStatus = 3; - TypeCmdScanResult = 4; - TypeRespScanResult = 5; -} - -message WiFiScanPayload { - WiFiScanMsgType msg = 1; - Status status = 2; - oneof payload { - CmdScanStart cmd_scan_start = 10; - RespScanStart resp_scan_start = 11; - CmdScanStatus cmd_scan_status = 12; - RespScanStatus resp_scan_status = 13; - CmdScanResult cmd_scan_result = 14; - RespScanResult resp_scan_result = 15; - } -} diff --git a/components/wifi_provisioning/python/wifi_config_pb2.py b/components/wifi_provisioning/python/wifi_config_pb2.py deleted file mode 100644 index 3d48ecfb7eb4..000000000000 --- a/components/wifi_provisioning/python/wifi_config_pb2.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: wifi_config.proto -"""Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -import constants_pb2 as constants__pb2 -import wifi_constants_pb2 as wifi__constants__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11wifi_config.proto\x1a\x0f\x63onstants.proto\x1a\x14wifi_constants.proto\"\x0e\n\x0c\x43mdGetStatus\"\xb2\x01\n\rRespGetStatus\x12\x17\n\x06status\x18\x01 \x01(\x0e\x32\x07.Status\x12$\n\tsta_state\x18\x02 \x01(\x0e\x32\x11.WifiStationState\x12/\n\x0b\x66\x61il_reason\x18\n \x01(\x0e\x32\x18.WifiConnectFailedReasonH\x00\x12(\n\tconnected\x18\x0b \x01(\x0b\x32\x13.WifiConnectedStateH\x00\x42\x07\n\x05state\"P\n\x0c\x43mdSetConfig\x12\x0c\n\x04ssid\x18\x01 \x01(\x0c\x12\x12\n\npassphrase\x18\x02 \x01(\x0c\x12\r\n\x05\x62ssid\x18\x03 \x01(\x0c\x12\x0f\n\x07\x63hannel\x18\x04 \x01(\x05\"(\n\rRespSetConfig\x12\x17\n\x06status\x18\x01 \x01(\x0e\x32\x07.Status\"\x10\n\x0e\x43mdApplyConfig\"*\n\x0fRespApplyConfig\x12\x17\n\x06status\x18\x01 \x01(\x0e\x32\x07.Status\"\xc3\x02\n\x11WiFiConfigPayload\x12\x1f\n\x03msg\x18\x01 \x01(\x0e\x32\x12.WiFiConfigMsgType\x12\'\n\x0e\x63md_get_status\x18\n \x01(\x0b\x32\r.CmdGetStatusH\x00\x12)\n\x0fresp_get_status\x18\x0b \x01(\x0b\x32\x0e.RespGetStatusH\x00\x12\'\n\x0e\x63md_set_config\x18\x0c \x01(\x0b\x32\r.CmdSetConfigH\x00\x12)\n\x0fresp_set_config\x18\r \x01(\x0b\x32\x0e.RespSetConfigH\x00\x12+\n\x10\x63md_apply_config\x18\x0e \x01(\x0b\x32\x0f.CmdApplyConfigH\x00\x12-\n\x11resp_apply_config\x18\x0f \x01(\x0b\x32\x10.RespApplyConfigH\x00\x42\t\n\x07payload*\x9e\x01\n\x11WiFiConfigMsgType\x12\x14\n\x10TypeCmdGetStatus\x10\x00\x12\x15\n\x11TypeRespGetStatus\x10\x01\x12\x14\n\x10TypeCmdSetConfig\x10\x02\x12\x15\n\x11TypeRespSetConfig\x10\x03\x12\x16\n\x12TypeCmdApplyConfig\x10\x04\x12\x17\n\x13TypeRespApplyConfig\x10\x05\x62\x06proto3') - -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wifi_config_pb2', globals()) -if _descriptor._USE_C_DESCRIPTORS == False: - - DESCRIPTOR._options = None - _WIFICONFIGMSGTYPE._serialized_start=770 - _WIFICONFIGMSGTYPE._serialized_end=928 - _CMDGETSTATUS._serialized_start=60 - _CMDGETSTATUS._serialized_end=74 - _RESPGETSTATUS._serialized_start=77 - _RESPGETSTATUS._serialized_end=255 - _CMDSETCONFIG._serialized_start=257 - _CMDSETCONFIG._serialized_end=337 - _RESPSETCONFIG._serialized_start=339 - _RESPSETCONFIG._serialized_end=379 - _CMDAPPLYCONFIG._serialized_start=381 - _CMDAPPLYCONFIG._serialized_end=397 - _RESPAPPLYCONFIG._serialized_start=399 - _RESPAPPLYCONFIG._serialized_end=441 - _WIFICONFIGPAYLOAD._serialized_start=444 - _WIFICONFIGPAYLOAD._serialized_end=767 -# @@protoc_insertion_point(module_scope) diff --git a/components/wifi_provisioning/python/wifi_constants_pb2.py b/components/wifi_provisioning/python/wifi_constants_pb2.py deleted file mode 100644 index 3165650d940e..000000000000 --- a/components/wifi_provisioning/python/wifi_constants_pb2.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: wifi_constants.proto -"""Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x14wifi_constants.proto\"v\n\x12WifiConnectedState\x12\x10\n\x08ip4_addr\x18\x01 \x01(\t\x12 \n\tauth_mode\x18\x02 \x01(\x0e\x32\r.WifiAuthMode\x12\x0c\n\x04ssid\x18\x03 \x01(\x0c\x12\r\n\x05\x62ssid\x18\x04 \x01(\x0c\x12\x0f\n\x07\x63hannel\x18\x05 \x01(\x05*Y\n\x10WifiStationState\x12\r\n\tConnected\x10\x00\x12\x0e\n\nConnecting\x10\x01\x12\x10\n\x0c\x44isconnected\x10\x02\x12\x14\n\x10\x43onnectionFailed\x10\x03*=\n\x17WifiConnectFailedReason\x12\r\n\tAuthError\x10\x00\x12\x13\n\x0fNetworkNotFound\x10\x01*\x84\x01\n\x0cWifiAuthMode\x12\x08\n\x04Open\x10\x00\x12\x07\n\x03WEP\x10\x01\x12\x0b\n\x07WPA_PSK\x10\x02\x12\x0c\n\x08WPA2_PSK\x10\x03\x12\x10\n\x0cWPA_WPA2_PSK\x10\x04\x12\x13\n\x0fWPA2_ENTERPRISE\x10\x05\x12\x0c\n\x08WPA3_PSK\x10\x06\x12\x11\n\rWPA2_WPA3_PSK\x10\x07\x62\x06proto3') - -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wifi_constants_pb2', globals()) -if _descriptor._USE_C_DESCRIPTORS == False: - - DESCRIPTOR._options = None - _WIFISTATIONSTATE._serialized_start=144 - _WIFISTATIONSTATE._serialized_end=233 - _WIFICONNECTFAILEDREASON._serialized_start=235 - _WIFICONNECTFAILEDREASON._serialized_end=296 - _WIFIAUTHMODE._serialized_start=299 - _WIFIAUTHMODE._serialized_end=431 - _WIFICONNECTEDSTATE._serialized_start=24 - _WIFICONNECTEDSTATE._serialized_end=142 -# @@protoc_insertion_point(module_scope) diff --git a/components/wifi_provisioning/python/wifi_ctrl_pb2.py b/components/wifi_provisioning/python/wifi_ctrl_pb2.py deleted file mode 100644 index 1057164e9ad1..000000000000 --- a/components/wifi_provisioning/python/wifi_ctrl_pb2.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: wifi_ctrl.proto -"""Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -import constants_pb2 as constants__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fwifi_ctrl.proto\x1a\x0f\x63onstants.proto\"\x0e\n\x0c\x43mdCtrlReset\"\x0f\n\rRespCtrlReset\"\x0f\n\rCmdCtrlReprov\"\x10\n\x0eRespCtrlReprov\"\x80\x02\n\x0fWiFiCtrlPayload\x12\x1d\n\x03msg\x18\x01 \x01(\x0e\x32\x10.WiFiCtrlMsgType\x12\x17\n\x06status\x18\x02 \x01(\x0e\x32\x07.Status\x12\'\n\x0e\x63md_ctrl_reset\x18\x0b \x01(\x0b\x32\r.CmdCtrlResetH\x00\x12)\n\x0fresp_ctrl_reset\x18\x0c \x01(\x0b\x32\x0e.RespCtrlResetH\x00\x12)\n\x0f\x63md_ctrl_reprov\x18\r \x01(\x0b\x32\x0e.CmdCtrlReprovH\x00\x12+\n\x10resp_ctrl_reprov\x18\x0e \x01(\x0b\x32\x0f.RespCtrlReprovH\x00\x42\t\n\x07payload*\x83\x01\n\x0fWiFiCtrlMsgType\x12\x14\n\x10TypeCtrlReserved\x10\x00\x12\x14\n\x10TypeCmdCtrlReset\x10\x01\x12\x15\n\x11TypeRespCtrlReset\x10\x02\x12\x15\n\x11TypeCmdCtrlReprov\x10\x03\x12\x16\n\x12TypeRespCtrlReprov\x10\x04\x62\x06proto3') - -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wifi_ctrl_pb2', globals()) -if _descriptor._USE_C_DESCRIPTORS == False: - - DESCRIPTOR._options = None - _WIFICTRLMSGTYPE._serialized_start=364 - _WIFICTRLMSGTYPE._serialized_end=495 - _CMDCTRLRESET._serialized_start=36 - _CMDCTRLRESET._serialized_end=50 - _RESPCTRLRESET._serialized_start=52 - _RESPCTRLRESET._serialized_end=67 - _CMDCTRLREPROV._serialized_start=69 - _CMDCTRLREPROV._serialized_end=84 - _RESPCTRLREPROV._serialized_start=86 - _RESPCTRLREPROV._serialized_end=102 - _WIFICTRLPAYLOAD._serialized_start=105 - _WIFICTRLPAYLOAD._serialized_end=361 -# @@protoc_insertion_point(module_scope) diff --git a/components/wifi_provisioning/python/wifi_scan_pb2.py b/components/wifi_provisioning/python/wifi_scan_pb2.py deleted file mode 100644 index aaf69c60f2ae..000000000000 --- a/components/wifi_provisioning/python/wifi_scan_pb2.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: wifi_scan.proto -"""Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -import constants_pb2 as constants__pb2 -import wifi_constants_pb2 as wifi__constants__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fwifi_scan.proto\x1a\x0f\x63onstants.proto\x1a\x14wifi_constants.proto\"\\\n\x0c\x43mdScanStart\x12\x10\n\x08\x62locking\x18\x01 \x01(\x08\x12\x0f\n\x07passive\x18\x02 \x01(\x08\x12\x16\n\x0egroup_channels\x18\x03 \x01(\r\x12\x11\n\tperiod_ms\x18\x04 \x01(\r\"\x0f\n\rRespScanStart\"\x0f\n\rCmdScanStatus\"=\n\x0eRespScanStatus\x12\x15\n\rscan_finished\x18\x01 \x01(\x08\x12\x14\n\x0cresult_count\x18\x02 \x01(\r\"3\n\rCmdScanResult\x12\x13\n\x0bstart_index\x18\x01 \x01(\r\x12\r\n\x05\x63ount\x18\x02 \x01(\r\"i\n\x0eWiFiScanResult\x12\x0c\n\x04ssid\x18\x01 \x01(\x0c\x12\x0f\n\x07\x63hannel\x18\x02 \x01(\r\x12\x0c\n\x04rssi\x18\x03 \x01(\x05\x12\r\n\x05\x62ssid\x18\x04 \x01(\x0c\x12\x1b\n\x04\x61uth\x18\x05 \x01(\x0e\x32\r.WifiAuthMode\"2\n\x0eRespScanResult\x12 \n\x07\x65ntries\x18\x01 \x03(\x0b\x32\x0f.WiFiScanResult\"\xd8\x02\n\x0fWiFiScanPayload\x12\x1d\n\x03msg\x18\x01 \x01(\x0e\x32\x10.WiFiScanMsgType\x12\x17\n\x06status\x18\x02 \x01(\x0e\x32\x07.Status\x12\'\n\x0e\x63md_scan_start\x18\n \x01(\x0b\x32\r.CmdScanStartH\x00\x12)\n\x0fresp_scan_start\x18\x0b \x01(\x0b\x32\x0e.RespScanStartH\x00\x12)\n\x0f\x63md_scan_status\x18\x0c \x01(\x0b\x32\x0e.CmdScanStatusH\x00\x12+\n\x10resp_scan_status\x18\r \x01(\x0b\x32\x0f.RespScanStatusH\x00\x12)\n\x0f\x63md_scan_result\x18\x0e \x01(\x0b\x32\x0e.CmdScanResultH\x00\x12+\n\x10resp_scan_result\x18\x0f \x01(\x0b\x32\x0f.RespScanResultH\x00\x42\t\n\x07payload*\x9c\x01\n\x0fWiFiScanMsgType\x12\x14\n\x10TypeCmdScanStart\x10\x00\x12\x15\n\x11TypeRespScanStart\x10\x01\x12\x15\n\x11TypeCmdScanStatus\x10\x02\x12\x16\n\x12TypeRespScanStatus\x10\x03\x12\x15\n\x11TypeCmdScanResult\x10\x04\x12\x16\n\x12TypeRespScanResult\x10\x05\x62\x06proto3') - -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wifi_scan_pb2', globals()) -if _descriptor._USE_C_DESCRIPTORS == False: - - DESCRIPTOR._options = None - _WIFISCANMSGTYPE._serialized_start=809 - _WIFISCANMSGTYPE._serialized_end=965 - _CMDSCANSTART._serialized_start=58 - _CMDSCANSTART._serialized_end=150 - _RESPSCANSTART._serialized_start=152 - _RESPSCANSTART._serialized_end=167 - _CMDSCANSTATUS._serialized_start=169 - _CMDSCANSTATUS._serialized_end=184 - _RESPSCANSTATUS._serialized_start=186 - _RESPSCANSTATUS._serialized_end=247 - _CMDSCANRESULT._serialized_start=249 - _CMDSCANRESULT._serialized_end=300 - _WIFISCANRESULT._serialized_start=302 - _WIFISCANRESULT._serialized_end=407 - _RESPSCANRESULT._serialized_start=409 - _RESPSCANRESULT._serialized_end=459 - _WIFISCANPAYLOAD._serialized_start=462 - _WIFISCANPAYLOAD._serialized_end=806 -# @@protoc_insertion_point(module_scope) diff --git a/components/wifi_provisioning/src/handlers.c b/components/wifi_provisioning/src/handlers.c deleted file mode 100644 index a3baaf243eb4..000000000000 --- a/components/wifi_provisioning/src/handlers.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include -#include - -#include "wifi_provisioning/wifi_config.h" -#include "wifi_provisioning/wifi_scan.h" -#include "wifi_ctrl.h" -#include "wifi_provisioning/manager.h" -#include "wifi_provisioning_priv.h" - -static const char *TAG = "wifi_prov_handlers"; - -/* Provide definition of wifi_prov_ctx_t */ -struct wifi_prov_ctx { - wifi_config_t wifi_cfg; -}; - -static wifi_config_t *get_config(wifi_prov_ctx_t **ctx) -{ - return (*ctx ? & (*ctx)->wifi_cfg : NULL); -} - -static wifi_config_t *new_config(wifi_prov_ctx_t **ctx) -{ - free(*ctx); - (*ctx) = (wifi_prov_ctx_t *) calloc(1, sizeof(wifi_prov_ctx_t)); - return get_config(ctx); -} - -static void free_config(wifi_prov_ctx_t **ctx) -{ - free(*ctx); - *ctx = NULL; -} - -static esp_err_t get_status_handler(wifi_prov_config_get_data_t *resp_data, wifi_prov_ctx_t **ctx) -{ - /* Initialize to zero */ - memset(resp_data, 0, sizeof(wifi_prov_config_get_data_t)); - - if (wifi_prov_mgr_get_wifi_state(&resp_data->wifi_state) != ESP_OK) { - ESP_LOGW(TAG, "Wi-Fi provisioning manager not running"); - return ESP_ERR_INVALID_STATE; - } - - if (resp_data->wifi_state == WIFI_PROV_STA_CONNECTED) { - ESP_LOGD(TAG, "Got state : connected"); - - /* IP Addr assigned to STA */ - esp_netif_ip_info_t ip_info; - esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &ip_info); - esp_ip4addr_ntoa(&ip_info.ip, resp_data->conn_info.ip_addr, sizeof(resp_data->conn_info.ip_addr)); - - - /* AP information to which STA is connected */ - wifi_ap_record_t ap_info; - esp_wifi_sta_get_ap_info(&ap_info); - memcpy(resp_data->conn_info.bssid, (char *)ap_info.bssid, sizeof(ap_info.bssid)); - memcpy(resp_data->conn_info.ssid, (char *)ap_info.ssid, sizeof(ap_info.ssid)); - resp_data->conn_info.channel = ap_info.primary; - resp_data->conn_info.auth_mode = ap_info.authmode; - - /* Tell manager to stop provisioning service */ - wifi_prov_mgr_done(); - } else if (resp_data->wifi_state == WIFI_PROV_STA_DISCONNECTED) { - ESP_LOGD(TAG, "Got state : disconnected"); - - /* If disconnected, convey reason */ - wifi_prov_mgr_get_wifi_disconnect_reason(&resp_data->fail_reason); - } else { - ESP_LOGD(TAG, "Got state : connecting"); - } - return ESP_OK; -} - -static esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data, wifi_prov_ctx_t **ctx) -{ - wifi_config_t *wifi_cfg = get_config(ctx); - if (wifi_cfg) { - free_config(ctx); - } - - wifi_cfg = new_config(ctx); - if (!wifi_cfg) { - ESP_LOGE(TAG, "Unable to allocate Wi-Fi config"); - return ESP_ERR_NO_MEM; - } - - ESP_LOGD(TAG, "Wi-Fi Credentials Received"); - - /* Using memcpy allows the max SSID length to be 32 bytes (as per 802.11 standard). - * But this doesn't guarantee that the saved SSID will be null terminated, because - * wifi_cfg->sta.ssid is also 32 bytes long (without extra 1 byte for null character). - * Although, this is not a matter for concern because esp_wifi library reads the SSID - * upto 32 bytes in absence of null termination */ - const size_t ssid_len = strnlen(req_data->ssid, sizeof(wifi_cfg->sta.ssid)); - /* Ensure SSID less than 32 bytes is null terminated */ - memset(wifi_cfg->sta.ssid, 0, sizeof(wifi_cfg->sta.ssid)); - memcpy(wifi_cfg->sta.ssid, req_data->ssid, ssid_len); - - /* Using strlcpy allows both max passphrase length (63 bytes) and ensures null termination - * because size of wifi_cfg->sta.password is 64 bytes (1 extra byte for null character) */ - strlcpy((char *) wifi_cfg->sta.password, req_data->password, sizeof(wifi_cfg->sta.password)); - -#ifdef CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN - wifi_cfg->sta.scan_method = WIFI_ALL_CHANNEL_SCAN; -#else /* CONFIG_WIFI_PROV_STA_FAST_SCAN */ - wifi_cfg->sta.scan_method = WIFI_FAST_SCAN; -#endif - - return ESP_OK; -} - -static esp_err_t apply_config_handler(wifi_prov_ctx_t **ctx) -{ - wifi_config_t *wifi_cfg = get_config(ctx); - if (!wifi_cfg) { - ESP_LOGE(TAG, "Wi-Fi config not set"); - return ESP_ERR_INVALID_STATE; - } - - esp_err_t ret = wifi_prov_mgr_configure_sta(wifi_cfg); - if (ret == ESP_OK) { - ESP_LOGD(TAG, "Wi-Fi Credentials Applied"); - } else { - ESP_LOGE(TAG, "Failed to apply Wi-Fi Credentials"); - } - - free_config(ctx); - return ret; -} - -esp_err_t get_wifi_prov_handlers(wifi_prov_config_handlers_t *ptr) -{ - if (!ptr) { - return ESP_ERR_INVALID_ARG; - } - ptr->get_status_handler = get_status_handler; - ptr->set_config_handler = set_config_handler; - ptr->apply_config_handler = apply_config_handler; - ptr->ctx = NULL; - return ESP_OK; -} - -/*************************************************************************/ - -static esp_err_t scan_start(bool blocking, bool passive, - uint8_t group_channels, uint32_t period_ms, - wifi_prov_scan_ctx_t **ctx) -{ - return wifi_prov_mgr_wifi_scan_start(blocking, passive, group_channels, period_ms); -} - -static esp_err_t scan_status(bool *scan_finished, - uint16_t *result_count, - wifi_prov_scan_ctx_t **ctx) -{ - *scan_finished = wifi_prov_mgr_wifi_scan_finished(); - *result_count = wifi_prov_mgr_wifi_scan_result_count(); - return ESP_OK; -} - -static esp_err_t scan_result(uint16_t result_index, - wifi_prov_scan_result_t *result, - wifi_prov_scan_ctx_t **ctx) -{ - const wifi_ap_record_t *record = wifi_prov_mgr_wifi_scan_result(result_index); - if (!record) { - return ESP_FAIL; - } - - /* Compile time check ensures memory safety in case SSID length in - * record / result structure definition changes in future */ - _Static_assert(sizeof(result->ssid) == sizeof(record->ssid), - "source and destination should be of same size"); - memcpy(result->ssid, record->ssid, sizeof(record->ssid)); - memcpy(result->bssid, record->bssid, sizeof(record->bssid)); - result->channel = record->primary; - result->rssi = record->rssi; - result->auth = record->authmode; - return ESP_OK; -} - -esp_err_t get_wifi_scan_handlers(wifi_prov_scan_handlers_t *ptr) -{ - if (!ptr) { - return ESP_ERR_INVALID_ARG; - } - ptr->scan_start = scan_start; - ptr->scan_status = scan_status; - ptr->scan_result = scan_result; - ptr->ctx = NULL; - return ESP_OK; -} - -/*************************************************************************/ - -static esp_err_t ctrl_reset(void) -{ - return wifi_prov_mgr_reset_sm_state_on_failure(); -} - -static esp_err_t ctrl_reprov(void) -{ - return wifi_prov_mgr_reset_sm_state_for_reprovision(); -} - -esp_err_t get_wifi_ctrl_handlers(wifi_ctrl_handlers_t *ptr) -{ - if (!ptr) { - return ESP_ERR_INVALID_ARG; - } - ptr->ctrl_reset = ctrl_reset; - ptr->ctrl_reprov = ctrl_reprov; - return ESP_OK; -} diff --git a/components/wifi_provisioning/src/manager.c b/components/wifi_provisioning/src/manager.c deleted file mode 100644 index c3b05383061d..000000000000 --- a/components/wifi_provisioning/src/manager.c +++ /dev/null @@ -1,1803 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "wifi_provisioning_priv.h" - -#define WIFI_PROV_MGR_VERSION "v1.1" -#define WIFI_PROV_STORAGE_BIT BIT0 -#define WIFI_PROV_SETTING_BIT BIT1 -#define MAX_SCAN_RESULTS CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES - -#define ACQUIRE_LOCK(mux) assert(xSemaphoreTake(mux, portMAX_DELAY) == pdTRUE) -#define RELEASE_LOCK(mux) assert(xSemaphoreGive(mux) == pdTRUE) - -static const char *TAG = "wifi_prov_mgr"; - -ESP_EVENT_DEFINE_BASE(WIFI_PROV_EVENT); -ESP_EVENT_DEFINE_BASE(WIFI_PROV_MGR_PVT_EVENT); - -typedef enum { - WIFI_PROV_STATE_IDLE, - WIFI_PROV_STATE_STARTING, - WIFI_PROV_STATE_STARTED, - WIFI_PROV_STATE_CRED_RECV, - WIFI_PROV_STATE_FAIL, - WIFI_PROV_STATE_SUCCESS, - WIFI_PROV_STATE_STOPPING -} wifi_prov_mgr_state_t; - -typedef enum { - WIFI_PROV_MGR_STOP, -} wifi_prov_mgr_pvt_event_t; - -/** - * @brief Structure for storing capabilities supported by - * the provisioning service - */ -struct wifi_prov_capabilities { - /* Security 0 is used */ - bool no_sec; - - /* Proof of Possession is not required for establishing session */ - bool no_pop; - - /* Provisioning doesn't stop on it's own after receiving Wi-Fi credentials - * instead application has to explicitly call wifi_prov_mgr_stop_provisioning() */ - bool no_auto_stop; -}; - -/** - * @brief Structure for storing miscellaneous information about - * provisioning service that will be conveyed to clients - */ -struct wifi_prov_info { - const char *version; - struct wifi_prov_capabilities capabilities; -}; - -/** - * @brief Context data for provisioning manager - */ -struct wifi_prov_mgr_ctx { - /* Provisioning manager configuration */ - wifi_prov_mgr_config_t mgr_config; - - /* State of the provisioning service */ - wifi_prov_mgr_state_t prov_state; - - /* Provisioning scheme configuration */ - void *prov_scheme_config; - - /* Protocomm handle */ - protocomm_t *pc; - - /* Type of security to use with protocomm */ - int security; - - /* Pointer to security params */ - const void* protocomm_sec_params; - - /* Handle for Provisioning Auto Stop timer */ - esp_timer_handle_t autostop_timer; - - /* Handle for delayed Wi-Fi connection timer */ - esp_timer_handle_t wifi_connect_timer; - - /* Handle for delayed cleanup timer */ - esp_timer_handle_t cleanup_delay_timer; - - /* State of Wi-Fi Station */ - wifi_prov_sta_state_t wifi_state; - - /* Code for Wi-Fi station disconnection (if disconnected) */ - wifi_prov_sta_fail_reason_t wifi_disconnect_reason; - - /* Protocomm handlers for Wi-Fi configuration endpoint */ - wifi_prov_config_handlers_t *wifi_prov_handlers; - - /* Protocomm handlers for Wi-Fi scan endpoint */ - wifi_prov_scan_handlers_t *wifi_scan_handlers; - - /* Protocomm handlers for Wi-Fi ctrl endpoint */ - wifi_ctrl_handlers_t *wifi_ctrl_handlers; - - /* Count of used endpoint UUIDs */ - unsigned int endpoint_uuid_used; - - /* Provisioning service information */ - struct wifi_prov_info mgr_info; - - /* Application related information in JSON format */ - cJSON *app_info_json; - - /* Delay after which resources will be cleaned up asynchronously - * upon execution of wifi_prov_mgr_stop_provisioning() */ - uint32_t cleanup_delay; - - /* Wi-Fi scan parameters and state variables */ - bool scanning; - uint8_t channels_per_group; - uint16_t curr_channel; - uint16_t ap_list_len[14]; // 14 entries corresponding to each channel - wifi_ap_record_t *ap_list[14]; - wifi_ap_record_t *ap_list_sorted[MAX_SCAN_RESULTS]; - wifi_scan_config_t scan_cfg; -}; - -/* Mutex to lock/unlock access to provisioning singleton - * context data. This is allocated only once on first init - * and never deleted as wifi_prov_mgr is a singleton */ -static SemaphoreHandle_t prov_ctx_lock = NULL; - -/* Pointer to provisioning context data */ -static struct wifi_prov_mgr_ctx *prov_ctx; - -/* This executes registered app_event_callback for a particular event - * - * NOTE : By the time this fucntion returns, it is possible that - * the manager got de-initialized due to a call to wifi_prov_mgr_deinit() - * either inside the event callbacks or from another thread. Therefore - * post execution of execute_event_cb(), the validity of prov_ctx must - * always be checked. A cleaner way, to avoid this pitfall safely, would - * be to limit the usage of this function to only public APIs, and that - * too at the very end, just before returning. - * - * NOTE: This function should be called only after ensuring that the - * context is valid and the control mutex is locked. */ -static void execute_event_cb(wifi_prov_cb_event_t event_id, void *event_data, size_t event_data_size) -{ - ESP_LOGD(TAG, "execute_event_cb : %d", event_id); - - if (prov_ctx) { - wifi_prov_cb_func_t app_cb = prov_ctx->mgr_config.app_event_handler.event_cb; - void *app_data = prov_ctx->mgr_config.app_event_handler.user_data; - - wifi_prov_cb_func_t scheme_cb = prov_ctx->mgr_config.scheme_event_handler.event_cb; - void *scheme_data = prov_ctx->mgr_config.scheme_event_handler.user_data; - - /* Release the mutex before executing the callbacks. This is done so that - * wifi_prov_mgr_event_handler() doesn't stay blocked for the duration */ - RELEASE_LOCK(prov_ctx_lock); - - if (scheme_cb) { - /* Call scheme specific event handler */ - scheme_cb(scheme_data, event_id, event_data); - } - - if (app_cb) { - /* Call application specific event handler */ - app_cb(app_data, event_id, event_data); - } - - if (esp_event_post(WIFI_PROV_EVENT, event_id, - event_data, event_data_size, - portMAX_DELAY) != ESP_OK) { - ESP_LOGE(TAG, "Failed to post event %d to default event loop", event_id); - } - - ACQUIRE_LOCK(prov_ctx_lock); - } -} - -esp_err_t wifi_prov_mgr_set_app_info(const char *label, const char *version, - const char**capabilities, size_t total_capabilities) -{ - if (!label || !version || !capabilities) { - return ESP_ERR_INVALID_ARG; - } - - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - esp_err_t ret = ESP_FAIL; - ACQUIRE_LOCK(prov_ctx_lock); - - if (prov_ctx && prov_ctx->prov_state == WIFI_PROV_STATE_IDLE) { - if (!prov_ctx->app_info_json) { - prov_ctx->app_info_json = cJSON_CreateObject(); - } - - cJSON *new_entry_json = cJSON_CreateObject(); - cJSON *capabilities_json = cJSON_CreateArray(); - cJSON_AddItemToObject(prov_ctx->app_info_json, label, new_entry_json); - - /* Version ("ver") */ - cJSON_AddStringToObject(new_entry_json, "ver", version); - - /* List of capabilities ("cap") */ - cJSON_AddItemToObject(new_entry_json, "cap", capabilities_json); - for (unsigned int i = 0; i < total_capabilities; i++) { - if (capabilities[i]) { - cJSON_AddItemToArray(capabilities_json, cJSON_CreateString(capabilities[i])); - } - } - ret = ESP_OK; - } else { - ret = ESP_ERR_INVALID_STATE; - } - - RELEASE_LOCK(prov_ctx_lock); - return ret; -} - -static cJSON* wifi_prov_get_info_json(void) -{ - cJSON *full_info_json = prov_ctx->app_info_json ? - cJSON_Duplicate(prov_ctx->app_info_json, 1) : cJSON_CreateObject(); - cJSON *prov_info_json = cJSON_CreateObject(); - cJSON *prov_capabilities = cJSON_CreateArray(); - - /* Use label "prov" to indicate provisioning related information */ - cJSON_AddItemToObject(full_info_json, "prov", prov_info_json); - - /* Version field */ - cJSON_AddStringToObject(prov_info_json, "ver", prov_ctx->mgr_info.version); - - cJSON_AddNumberToObject(prov_info_json, "sec_ver", prov_ctx->security); - /* Capabilities field */ - cJSON_AddItemToObject(prov_info_json, "cap", prov_capabilities); - - /* If Security / Proof of Possession is not used, indicate in capabilities */ - if (prov_ctx->mgr_info.capabilities.no_sec) { - cJSON_AddItemToArray(prov_capabilities, cJSON_CreateString("no_sec")); - } else if (prov_ctx->mgr_info.capabilities.no_pop) { - cJSON_AddItemToArray(prov_capabilities, cJSON_CreateString("no_pop")); - } - - /* Indicate capability for performing Wi-Fi scan */ - cJSON_AddItemToArray(prov_capabilities, cJSON_CreateString("wifi_scan")); - return full_info_json; -} - -/* Declare the internal event handler */ -static void wifi_prov_mgr_event_handler_internal(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data); - -static esp_err_t wifi_prov_mgr_start_service(const char *service_name, const char *service_key) -{ - const wifi_prov_scheme_t *scheme = &prov_ctx->mgr_config.scheme; - esp_err_t ret; - - /* Create new protocomm instance */ - prov_ctx->pc = protocomm_new(); - if (prov_ctx->pc == NULL) { - ESP_LOGE(TAG, "Failed to create new protocomm instance"); - return ESP_FAIL; - } - - ret = scheme->set_config_service(prov_ctx->prov_scheme_config, service_name, service_key); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to configure service"); - protocomm_delete(prov_ctx->pc); - return ret; - } - - /* Start provisioning */ - ret = scheme->prov_start(prov_ctx->pc, prov_ctx->prov_scheme_config); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to start service"); - protocomm_delete(prov_ctx->pc); - return ret; - } - - /* Set version information / capabilities of provisioning service and application */ - cJSON *version_json = wifi_prov_get_info_json(); - char *version_str = cJSON_Print(version_json); - ret = protocomm_set_version(prov_ctx->pc, "proto-ver", version_str); - free(version_str); - cJSON_Delete(version_json); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set version endpoint"); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - /* Set protocomm security type for endpoint */ - if (prov_ctx->security == 0) { -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_0 - ret = protocomm_set_security(prov_ctx->pc, "prov-session", - &protocomm_security0, NULL); -#else - // Enable SECURITY_VERSION_0 in Protocomm configuration menu - return ESP_ERR_NOT_SUPPORTED; -#endif - } else if (prov_ctx->security == 1) { -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1 - ret = protocomm_set_security(prov_ctx->pc, "prov-session", - &protocomm_security1, prov_ctx->protocomm_sec_params); -#else - // Enable SECURITY_VERSION_1 in Protocomm configuration menu - return ESP_ERR_NOT_SUPPORTED; -#endif - } else if (prov_ctx->security == 2) { -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2 - ret = protocomm_set_security(prov_ctx->pc, "prov-session", - &protocomm_security2, prov_ctx->protocomm_sec_params); -#else - // Enable SECURITY_VERSION_2 in Protocomm configuration menu - return ESP_ERR_NOT_SUPPORTED; -#endif - } else { - ESP_LOGE(TAG, "Unsupported protocomm security version %d", prov_ctx->security); - ret = ESP_ERR_INVALID_ARG; - } - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set security endpoint"); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - prov_ctx->wifi_prov_handlers = malloc(sizeof(wifi_prov_config_handlers_t)); - ret = get_wifi_prov_handlers(prov_ctx->wifi_prov_handlers); - if (ret != ESP_OK) { - ESP_LOGD(TAG, "Failed to allocate memory for provisioning handlers"); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ESP_ERR_NO_MEM; - } - - /* Add protocomm endpoint for Wi-Fi station configuration */ - ret = protocomm_add_endpoint(prov_ctx->pc, "prov-config", - wifi_prov_config_data_handler, - prov_ctx->wifi_prov_handlers); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set provisioning endpoint"); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - prov_ctx->wifi_scan_handlers = malloc(sizeof(wifi_prov_scan_handlers_t)); - ret = get_wifi_scan_handlers(prov_ctx->wifi_scan_handlers); - if (ret != ESP_OK) { - ESP_LOGD(TAG, "Failed to allocate memory for Wi-Fi scan handlers"); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ESP_ERR_NO_MEM; - } - - /* Add endpoint for scanning Wi-Fi APs and sending scan list */ - ret = protocomm_add_endpoint(prov_ctx->pc, "prov-scan", - wifi_prov_scan_handler, - prov_ctx->wifi_scan_handlers); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi scan endpoint"); - free(prov_ctx->wifi_scan_handlers); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - prov_ctx->wifi_ctrl_handlers = malloc(sizeof(wifi_ctrl_handlers_t)); - ret = get_wifi_ctrl_handlers(prov_ctx->wifi_ctrl_handlers); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to allocate memory for Wi-Fi ctrl handlers"); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ESP_ERR_NO_MEM; - } - - /* Add endpoint for controlling state of Wi-Fi station */ - ret = protocomm_add_endpoint(prov_ctx->pc, "prov-ctrl", - wifi_ctrl_handler, - prov_ctx->wifi_ctrl_handlers); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi ctrl endpoint"); - free(prov_ctx->wifi_ctrl_handlers); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - /* Register global event handler */ - ret = esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, - wifi_prov_mgr_event_handler_internal, NULL); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to register WiFi event handler"); - free(prov_ctx->wifi_scan_handlers); - free(prov_ctx->wifi_ctrl_handlers); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - ret = esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, - wifi_prov_mgr_event_handler_internal, NULL); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to register IP event handler"); - esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, - wifi_prov_mgr_event_handler_internal); - free(prov_ctx->wifi_scan_handlers); - free(prov_ctx->wifi_ctrl_handlers); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - ret = esp_event_handler_register(WIFI_PROV_MGR_PVT_EVENT, WIFI_PROV_MGR_STOP, - wifi_prov_mgr_event_handler_internal, NULL); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to register provisioning event handler"); - esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, - wifi_prov_mgr_event_handler_internal); - esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, - wifi_prov_mgr_event_handler_internal); - free(prov_ctx->wifi_scan_handlers); - free(prov_ctx->wifi_ctrl_handlers); - free(prov_ctx->wifi_prov_handlers); - scheme->prov_stop(prov_ctx->pc); - protocomm_delete(prov_ctx->pc); - return ret; - } - - - ESP_LOGI(TAG, "Provisioning started with service name : %s ", - service_name ? service_name : ""); - return ESP_OK; -} - -esp_err_t wifi_prov_mgr_endpoint_create(const char *ep_name) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - esp_err_t err = ESP_FAIL; - - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx && - prov_ctx->prov_state == WIFI_PROV_STATE_IDLE) { - err = prov_ctx->mgr_config.scheme.set_config_endpoint( - prov_ctx->prov_scheme_config, ep_name, - prov_ctx->endpoint_uuid_used + 1); - } - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to create additional endpoint"); - } else { - prov_ctx->endpoint_uuid_used++; - } - RELEASE_LOCK(prov_ctx_lock); - return err; -} - -esp_err_t wifi_prov_mgr_endpoint_register(const char *ep_name, protocomm_req_handler_t handler, void *user_ctx) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - esp_err_t err = ESP_FAIL; - - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx && - prov_ctx->prov_state > WIFI_PROV_STATE_STARTING && - prov_ctx->prov_state < WIFI_PROV_STATE_STOPPING) { - err = protocomm_add_endpoint(prov_ctx->pc, ep_name, handler, user_ctx); - } - RELEASE_LOCK(prov_ctx_lock); - - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to register handler for endpoint"); - } - return err; -} - -void wifi_prov_mgr_endpoint_unregister(const char *ep_name) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx && - prov_ctx->prov_state > WIFI_PROV_STATE_STARTING && - prov_ctx->prov_state < WIFI_PROV_STATE_STOPPING) { - protocomm_remove_endpoint(prov_ctx->pc, ep_name); - } - RELEASE_LOCK(prov_ctx_lock); -} - -static void prov_stop_and_notify(bool is_async) -{ - esp_event_handler_unregister(WIFI_PROV_MGR_PVT_EVENT, WIFI_PROV_MGR_STOP, - wifi_prov_mgr_event_handler_internal); - - if (prov_ctx->cleanup_delay_timer) { - esp_timer_stop(prov_ctx->cleanup_delay_timer); - esp_timer_delete(prov_ctx->cleanup_delay_timer); - prov_ctx->cleanup_delay_timer = NULL; - } - - wifi_prov_cb_func_t app_cb = prov_ctx->mgr_config.app_event_handler.event_cb; - void *app_data = prov_ctx->mgr_config.app_event_handler.user_data; - - wifi_prov_cb_func_t scheme_cb = prov_ctx->mgr_config.scheme_event_handler.event_cb; - void *scheme_data = prov_ctx->mgr_config.scheme_event_handler.user_data; - - /* This delay is so that the client side app is notified first - * and then the provisioning is stopped. Generally 1000ms is enough. */ - if (!is_async) - { - uint32_t cleanup_delay = prov_ctx->cleanup_delay > 100 ? prov_ctx->cleanup_delay : 100; - vTaskDelay(cleanup_delay / portTICK_PERIOD_MS); - } - - protocomm_remove_endpoint(prov_ctx->pc, "prov-ctrl"); - - protocomm_remove_endpoint(prov_ctx->pc, "prov-scan"); - - protocomm_remove_endpoint(prov_ctx->pc, "prov-config"); - - protocomm_unset_security(prov_ctx->pc, "prov-session"); - - protocomm_unset_version(prov_ctx->pc, "proto-ver"); - - /* All the extra application added endpoints are also - * removed automatically when prov_stop is called */ - prov_ctx->mgr_config.scheme.prov_stop(prov_ctx->pc); - - /* Delete protocomm instance */ - protocomm_delete(prov_ctx->pc); - prov_ctx->pc = NULL; - - /* Free provisioning handlers */ - free(prov_ctx->wifi_prov_handlers->ctx); - free(prov_ctx->wifi_prov_handlers); - prov_ctx->wifi_prov_handlers = NULL; - - free(prov_ctx->wifi_scan_handlers->ctx); - free(prov_ctx->wifi_scan_handlers); - prov_ctx->wifi_scan_handlers = NULL; - - free(prov_ctx->wifi_ctrl_handlers); - prov_ctx->wifi_ctrl_handlers = NULL; - - /* Switch device to Wi-Fi STA mode irrespective of - * whether provisioning was completed or not */ - esp_wifi_set_mode(WIFI_MODE_STA); - ESP_LOGI(TAG, "Provisioning stopped"); - - if (is_async) { - /* NOTE: While calling this API in an async fashion, - * the context lock prov_ctx_lock has already been taken - */ - prov_ctx->prov_state = WIFI_PROV_STATE_IDLE; - - ESP_LOGD(TAG, "execute_event_cb : %d", WIFI_PROV_END); - if (scheme_cb) { - scheme_cb(scheme_data, WIFI_PROV_END, NULL); - } - if (app_cb) { - app_cb(app_data, WIFI_PROV_END, NULL); - } - if (esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_END, NULL, 0, portMAX_DELAY) != ESP_OK) { - ESP_LOGE(TAG, "Failed to post event WIFI_PROV_END"); - } - } -} - -/* This will do one of these: - * 1) if blocking is false, start a cleanup timer for stopping the provisioning service (returns true) - * 2) if blocking is true, stop provisioning service immediately (returns true) - * 3) if service was already in the process of termination, in blocking mode this will - * wait till the service is stopped (returns false) - * 4) if service was not running, this will return immediately (returns false) - * - * NOTE: This function should be called only after ensuring that the context - * is valid and the control mutex is locked - * - * NOTE: When blocking mode is selected, the event callbacks are not executed. - * This help with de-initialization. - */ -static bool wifi_prov_mgr_stop_service(bool blocking) -{ - if (blocking) { - /* Wait for any ongoing calls to wifi_prov_mgr_start_service() or - * wifi_prov_mgr_stop_service() from another thread to finish */ - while (prov_ctx && ( - prov_ctx->prov_state == WIFI_PROV_STATE_STARTING || - prov_ctx->prov_state == WIFI_PROV_STATE_STOPPING)) { - RELEASE_LOCK(prov_ctx_lock); - vTaskDelay(100 / portTICK_PERIOD_MS); - ACQUIRE_LOCK(prov_ctx_lock); - } - } else { - /* Wait for any ongoing call to wifi_prov_mgr_start_service() - * from another thread to finish */ - while (prov_ctx && - prov_ctx->prov_state == WIFI_PROV_STATE_STARTING) { - RELEASE_LOCK(prov_ctx_lock); - vTaskDelay(100 / portTICK_PERIOD_MS); - ACQUIRE_LOCK(prov_ctx_lock); - } - - if (prov_ctx && prov_ctx->prov_state == WIFI_PROV_STATE_STOPPING) { - ESP_LOGD(TAG, "Provisioning is already stopping"); - return false; - } - } - - if (!prov_ctx || prov_ctx->prov_state == WIFI_PROV_STATE_IDLE) { - ESP_LOGD(TAG, "Provisioning not running"); - return false; - } - - /* Timers not needed anymore */ - if (prov_ctx->autostop_timer) { - esp_timer_stop(prov_ctx->autostop_timer); - esp_timer_delete(prov_ctx->autostop_timer); - prov_ctx->autostop_timer = NULL; - } - - if (prov_ctx->wifi_connect_timer) { - esp_timer_stop(prov_ctx->wifi_connect_timer); - esp_timer_delete(prov_ctx->wifi_connect_timer); - prov_ctx->wifi_connect_timer = NULL; - } - - ESP_LOGD(TAG, "Stopping provisioning"); - prov_ctx->prov_state = WIFI_PROV_STATE_STOPPING; - - /* Free proof of possession */ - if (prov_ctx->protocomm_sec_params) { - if (prov_ctx->security == 1) { - // In case of security 1 we keep an internal copy of "pop". - // Hence free it at this point - uint8_t *pop = (uint8_t *)((protocomm_security1_params_t *) prov_ctx->protocomm_sec_params)->data; - free(pop); - } - prov_ctx->protocomm_sec_params = NULL; - } - - /* Delete all scan results */ - for (uint16_t channel = 0; channel < 14; channel++) { - free(prov_ctx->ap_list[channel]); - prov_ctx->ap_list[channel] = NULL; - } - prov_ctx->scanning = false; - for (uint8_t i = 0; i < MAX_SCAN_RESULTS; i++) { - prov_ctx->ap_list_sorted[i] = NULL; - } - - /* Remove event handler */ - esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, - wifi_prov_mgr_event_handler_internal); - esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, - wifi_prov_mgr_event_handler_internal); - - if (blocking) { - /* Run the cleanup without launching a separate task. Also the - * WIFI_PROV_END event is not emitted in this case */ - RELEASE_LOCK(prov_ctx_lock); - prov_stop_and_notify(false); - ACQUIRE_LOCK(prov_ctx_lock); - prov_ctx->prov_state = WIFI_PROV_STATE_IDLE; - } else { - /* Launch cleanup timer to perform the cleanup asynchronously. - * It is important to do this asynchronously because, there are - * situations in which the transport level resources have to be - * released - some duration after - returning from a call to - * wifi_prov_mgr_stop_provisioning(), like when it is called - * inside a protocomm handler */ - uint64_t cleanup_delay_ms = prov_ctx->cleanup_delay > 100 ? prov_ctx->cleanup_delay : 100; - esp_timer_start_once(prov_ctx->cleanup_delay_timer, cleanup_delay_ms * 1000U); - ESP_LOGD(TAG, "Provisioning scheduled for stopping"); - } - return true; -} - -/* Task spawned by timer callback */ -static void stop_prov_timer_cb(void *arg) -{ - wifi_prov_mgr_stop_provisioning(); -} - -static void cleanup_delay_timer_cb(void *arg) -{ - esp_err_t ret = esp_event_post(WIFI_PROV_MGR_PVT_EVENT, WIFI_PROV_MGR_STOP, NULL, 0, pdMS_TO_TICKS(100)); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to post WIFI_PROV_MGR_STOP event! %d %s", ret, esp_err_to_name(ret)); - } -} - -esp_err_t wifi_prov_mgr_disable_auto_stop(uint32_t cleanup_delay) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - esp_err_t ret = ESP_FAIL; - ACQUIRE_LOCK(prov_ctx_lock); - - if (prov_ctx && prov_ctx->prov_state == WIFI_PROV_STATE_IDLE) { - prov_ctx->mgr_info.capabilities.no_auto_stop = true; - prov_ctx->cleanup_delay = cleanup_delay; - ret = ESP_OK; - } else { - ret = ESP_ERR_INVALID_STATE; - } - - RELEASE_LOCK(prov_ctx_lock); - return ret; -} - -/* Call this if provisioning is completed before the timeout occurs */ -esp_err_t wifi_prov_mgr_done(void) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - bool auto_stop_enabled = false; - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx && !prov_ctx->mgr_info.capabilities.no_auto_stop) { - auto_stop_enabled = true; - } - RELEASE_LOCK(prov_ctx_lock); - - /* Stop provisioning if auto stop is enabled */ - if (auto_stop_enabled) { - wifi_prov_mgr_stop_provisioning(); - } - return ESP_OK; -} - -static esp_err_t update_wifi_scan_results(void) -{ - if (!prov_ctx->scanning) { - return ESP_ERR_INVALID_STATE; - } - ESP_LOGD(TAG, "Scan finished"); - - esp_err_t ret = ESP_FAIL; - uint16_t count = 0; - uint16_t curr_channel = prov_ctx->curr_channel; - - if (prov_ctx->ap_list[curr_channel]) { - free(prov_ctx->ap_list[curr_channel]); - prov_ctx->ap_list[curr_channel] = NULL; - prov_ctx->ap_list_len[curr_channel] = 0; - } - - if (esp_wifi_scan_get_ap_num(&count) != ESP_OK) { - ESP_LOGE(TAG, "Failed to get count of scanned APs"); - goto exit; - } - - if (!count) { - ESP_LOGD(TAG, "Scan result empty"); - ret = ESP_OK; - goto exit; - } - - uint16_t get_count = MIN(count, MAX_SCAN_RESULTS); - prov_ctx->ap_list[curr_channel] = (wifi_ap_record_t *) calloc(get_count, sizeof(wifi_ap_record_t)); - if (!prov_ctx->ap_list[curr_channel]) { - ESP_LOGE(TAG, "Failed to allocate memory for AP list"); - esp_wifi_clear_ap_list(); - goto exit; - } - if (esp_wifi_scan_get_ap_records(&get_count, prov_ctx->ap_list[curr_channel]) != ESP_OK) { - ESP_LOGE(TAG, "Failed to get scanned AP records"); - goto exit; - } - prov_ctx->ap_list_len[curr_channel] = get_count; - - if (prov_ctx->channels_per_group) { - ESP_LOGD(TAG, "Scan results for channel %d :", curr_channel); - } else { - ESP_LOGD(TAG, "Scan results :"); - } - ESP_LOGD(TAG, "\tS.N. %-32s %-12s %s %s", "SSID", "BSSID", "RSSI", "AUTH"); - for (uint8_t i = 0; i < prov_ctx->ap_list_len[curr_channel]; i++) { - ESP_LOGD(TAG, "\t[%2d] %-32s %02x%02x%02x%02x%02x%02x %4d %4d", i, - prov_ctx->ap_list[curr_channel][i].ssid, - prov_ctx->ap_list[curr_channel][i].bssid[0], - prov_ctx->ap_list[curr_channel][i].bssid[1], - prov_ctx->ap_list[curr_channel][i].bssid[2], - prov_ctx->ap_list[curr_channel][i].bssid[3], - prov_ctx->ap_list[curr_channel][i].bssid[4], - prov_ctx->ap_list[curr_channel][i].bssid[5], - prov_ctx->ap_list[curr_channel][i].rssi, - prov_ctx->ap_list[curr_channel][i].authmode); - } - - /* Store results in sorted list */ - { - int rc = get_count; - int is = MAX_SCAN_RESULTS - rc - 1; - while (rc > 0 && is >= 0) { - if (prov_ctx->ap_list_sorted[is]) { - if (prov_ctx->ap_list_sorted[is]->rssi > prov_ctx->ap_list[curr_channel][rc - 1].rssi) { - prov_ctx->ap_list_sorted[is + rc] = &prov_ctx->ap_list[curr_channel][rc - 1]; - rc--; - continue; - } - prov_ctx->ap_list_sorted[is + rc] = prov_ctx->ap_list_sorted[is]; - } - is--; - } - while (rc > 0) { - prov_ctx->ap_list_sorted[rc - 1] = &prov_ctx->ap_list[curr_channel][rc - 1]; - rc--; - } - } - - ret = ESP_OK; - exit: - - if (!prov_ctx->channels_per_group) { - /* All channel scan was performed - * so nothing more to do */ - prov_ctx->scanning = false; - goto final; - } - - curr_channel = prov_ctx->curr_channel = (prov_ctx->curr_channel + 1) % 14; - if (ret != ESP_OK || curr_channel == 0) { - prov_ctx->scanning = false; - goto final; - } - - if ((curr_channel % prov_ctx->channels_per_group) == 0) { - vTaskDelay(120 / portTICK_PERIOD_MS); - } - - ESP_LOGD(TAG, "Scan starting on channel %u...", curr_channel); - prov_ctx->scan_cfg.channel = curr_channel; - ret = esp_wifi_scan_start(&prov_ctx->scan_cfg, false); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to start scan"); - prov_ctx->scanning = false; - goto final; - } - ESP_LOGD(TAG, "Scan started"); - - final: - - return ret; -} - -static void wifi_prov_mgr_event_handler_internal( - void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return; - } - - ACQUIRE_LOCK(prov_ctx_lock); - - /* If pointer to provisioning application data is NULL - * then provisioning manager is not running, therefore - * return with error to allow the global handler to act */ - if (!prov_ctx) { - RELEASE_LOCK(prov_ctx_lock); - return; - } - - /* If scan completed then update scan result */ - if (prov_ctx->prov_state == WIFI_PROV_STATE_STARTED && - event_base == WIFI_EVENT && - event_id == WIFI_EVENT_SCAN_DONE) { - update_wifi_scan_results(); - } - - /* Only handle events when credential is received and - * Wi-Fi STA is yet to complete trying the connection */ - if (prov_ctx->prov_state < WIFI_PROV_STATE_CRED_RECV) { - RELEASE_LOCK(prov_ctx_lock); - return; - } - - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { - ESP_LOGI(TAG, "STA Start"); - /* Once configuration is received through protocomm, - * device is started as station. Once station starts, - * wait for connection to establish with configured - * host SSID and password */ - prov_ctx->wifi_state = WIFI_PROV_STA_CONNECTING; - } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { - ESP_LOGI(TAG, "STA Got IP"); - /* Station got IP. That means configuration is successful. */ - prov_ctx->wifi_state = WIFI_PROV_STA_CONNECTED; - prov_ctx->prov_state = WIFI_PROV_STATE_SUCCESS; - - /* If auto stop is enabled (default), schedule timer to - * stop provisioning after configured timeout. */ - if (!prov_ctx->mgr_info.capabilities.no_auto_stop) { - ESP_LOGD(TAG, "Starting %d sec timer for stop_prov_timer_cb()", - CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT); - esp_timer_start_once(prov_ctx->autostop_timer, CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT * 1000000U); - } - - /* Execute user registered callback handler */ - execute_event_cb(WIFI_PROV_CRED_SUCCESS, NULL, 0); - } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { - ESP_LOGE(TAG, "STA Disconnected"); - /* Station couldn't connect to configured host SSID */ - prov_ctx->wifi_state = WIFI_PROV_STA_DISCONNECTED; - - wifi_event_sta_disconnected_t* disconnected = (wifi_event_sta_disconnected_t*) event_data; - ESP_LOGE(TAG, "Disconnect reason : %d", disconnected->reason); - - /* Set code corresponding to the reason for disconnection */ - switch (disconnected->reason) { - case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT: - case WIFI_REASON_AUTH_FAIL: - case WIFI_REASON_HANDSHAKE_TIMEOUT: - case WIFI_REASON_MIC_FAILURE: - ESP_LOGE(TAG, "STA Auth Error"); - prov_ctx->wifi_disconnect_reason = WIFI_PROV_STA_AUTH_ERROR; - break; - case WIFI_REASON_NO_AP_FOUND: - ESP_LOGE(TAG, "STA AP Not found"); - prov_ctx->wifi_disconnect_reason = WIFI_PROV_STA_AP_NOT_FOUND; - break; - default: - /* If none of the expected reasons, - * retry connecting to host SSID */ - prov_ctx->wifi_state = WIFI_PROV_STA_CONNECTING; - esp_wifi_connect(); - } - - /* In case of disconnection, update state of service and - * run the event handler with disconnection reason as data */ - if (prov_ctx->wifi_state == WIFI_PROV_STA_DISCONNECTED) { - prov_ctx->prov_state = WIFI_PROV_STATE_FAIL; - wifi_prov_sta_fail_reason_t reason = prov_ctx->wifi_disconnect_reason; - /* Execute user registered callback handler */ - execute_event_cb(WIFI_PROV_CRED_FAIL, (void *)&reason, sizeof(reason)); - } - } else if (event_base == WIFI_PROV_MGR_PVT_EVENT && event_id == WIFI_PROV_MGR_STOP) { - prov_stop_and_notify(true); - } - - RELEASE_LOCK(prov_ctx_lock); -} - -esp_err_t wifi_prov_mgr_wifi_scan_start(bool blocking, bool passive, - uint8_t group_channels, uint32_t period_ms) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - ACQUIRE_LOCK(prov_ctx_lock); - - if (!prov_ctx) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_ERR_INVALID_STATE; - } - - if (prov_ctx->scanning) { - ESP_LOGD(TAG, "Scan already running"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_OK; - } - - /* Clear sorted list for new entries */ - for (uint8_t i = 0; i < MAX_SCAN_RESULTS; i++) { - prov_ctx->ap_list_sorted[i] = NULL; - } - - if (passive) { - prov_ctx->scan_cfg.scan_type = WIFI_SCAN_TYPE_PASSIVE; -/* We do not recommend scan configuration modification in Wi-Fi and BT coexistence mode */ -#if !CONFIG_BT_ENABLED - prov_ctx->scan_cfg.scan_time.passive = period_ms; -#endif - } else { - prov_ctx->scan_cfg.scan_type = WIFI_SCAN_TYPE_ACTIVE; -/* We do not recommend scan configuration modification in Wi-Fi and BT coexistence mode */ -#if !CONFIG_BT_ENABLED - prov_ctx->scan_cfg.scan_time.active.min = period_ms; - prov_ctx->scan_cfg.scan_time.active.max = period_ms; -#endif - } - prov_ctx->channels_per_group = group_channels; - - if (prov_ctx->channels_per_group) { - ESP_LOGD(TAG, "Scan starting on channel 1..."); - prov_ctx->scan_cfg.channel = 1; - } else { - ESP_LOGD(TAG, "Scan starting..."); - prov_ctx->scan_cfg.channel = 0; - } - - if (esp_wifi_scan_start(&prov_ctx->scan_cfg, false) != ESP_OK) { - ESP_LOGE(TAG, "Failed to start scan"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - - ESP_LOGD(TAG, "Scan started"); - prov_ctx->scanning = true; - prov_ctx->curr_channel = prov_ctx->scan_cfg.channel; - RELEASE_LOCK(prov_ctx_lock); - - /* If scan is to be non-blocking, return immediately */ - if (!blocking) { - return ESP_OK; - } - - /* Loop till scan is complete */ - bool scanning = true; - while (scanning) { - ACQUIRE_LOCK(prov_ctx_lock); - scanning = (prov_ctx && prov_ctx->scanning); - RELEASE_LOCK(prov_ctx_lock); - - /* 120ms delay is sufficient for Wi-Fi beacons to be sent */ - vTaskDelay(120 / portTICK_PERIOD_MS); - } - return ESP_OK; -} - -bool wifi_prov_mgr_wifi_scan_finished(void) -{ - bool scan_finished = true; - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return scan_finished; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (!prov_ctx) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - RELEASE_LOCK(prov_ctx_lock); - return scan_finished; - } - - scan_finished = !prov_ctx->scanning; - RELEASE_LOCK(prov_ctx_lock); - return scan_finished; -} - -uint16_t wifi_prov_mgr_wifi_scan_result_count(void) -{ - uint16_t rval = 0; - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return rval; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (!prov_ctx) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - RELEASE_LOCK(prov_ctx_lock); - return rval; - } - - while (rval < MAX_SCAN_RESULTS) { - if (!prov_ctx->ap_list_sorted[rval]) { - break; - } - rval++; - } - RELEASE_LOCK(prov_ctx_lock); - return rval; -} - -const wifi_ap_record_t *wifi_prov_mgr_wifi_scan_result(uint16_t index) -{ - const wifi_ap_record_t *rval = NULL; - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return rval; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (!prov_ctx) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - RELEASE_LOCK(prov_ctx_lock); - return rval; - } - - if (index < MAX_SCAN_RESULTS) { - rval = prov_ctx->ap_list_sorted[index]; - } - RELEASE_LOCK(prov_ctx_lock); - return rval; -} - -esp_err_t wifi_prov_mgr_get_wifi_state(wifi_prov_sta_state_t *state) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx == NULL || state == NULL) { - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - - *state = prov_ctx->wifi_state; - RELEASE_LOCK(prov_ctx_lock); - return ESP_OK; -} - -esp_err_t wifi_prov_mgr_get_wifi_disconnect_reason(wifi_prov_sta_fail_reason_t *reason) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx == NULL || reason == NULL) { - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - - if (prov_ctx->wifi_state != WIFI_PROV_STA_DISCONNECTED) { - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - - *reason = prov_ctx->wifi_disconnect_reason; - RELEASE_LOCK(prov_ctx_lock); - return ESP_OK; -} - -static void debug_print_wifi_credentials(wifi_sta_config_t sta, const char* pretext) -{ - size_t passlen = strlen((const char*) sta.password); - ESP_LOGD(TAG, "%s Wi-Fi SSID : %.*s", pretext, - strnlen((const char *) sta.ssid, sizeof(sta.ssid)), (const char *) sta.ssid); - - if (passlen) { - /* Mask password partially if longer than 3, else mask it completely */ - memset(sta.password + (passlen > 3), '*', passlen - 2*(passlen > 3)); - ESP_LOGD(TAG, "%s Wi-Fi Password : %s", pretext, (const char *) sta.password); - } -} - -esp_err_t wifi_prov_mgr_is_provisioned(bool *provisioned) -{ - if (!provisioned) { - return ESP_ERR_INVALID_ARG; - } - - *provisioned = false; - - /* Get Wi-Fi Station configuration */ - wifi_config_t wifi_cfg; - if (esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) { - return ESP_FAIL; - } - - if (strlen((const char *) wifi_cfg.sta.ssid)) { - *provisioned = true; - debug_print_wifi_credentials(wifi_cfg.sta, "Found"); - } - return ESP_OK; -} - -bool wifi_prov_mgr_is_sm_idle(void) -{ - return (prov_ctx->prov_state == WIFI_PROV_STATE_IDLE); -} - -static void wifi_connect_timer_cb(void *arg) -{ - if (esp_wifi_connect() != ESP_OK) { - ESP_LOGE(TAG, "Failed to connect Wi-Fi"); - } -} - -esp_err_t wifi_prov_mgr_configure_sta(wifi_config_t *wifi_cfg) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (!prov_ctx) { - ESP_LOGE(TAG, "Invalid state of Provisioning app"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - if (prov_ctx->prov_state >= WIFI_PROV_STATE_CRED_RECV) { - ESP_LOGE(TAG, "Wi-Fi credentials already received by provisioning app"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - debug_print_wifi_credentials(wifi_cfg->sta, "Received"); - - /* Configure Wi-Fi as both AP and/or Station */ - if (esp_wifi_set_mode(prov_ctx->mgr_config.scheme.wifi_mode) != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi mode"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - - /* Don't release mutex yet as it is possible that right after - * esp_wifi_connect() is called below, the related Wi-Fi event - * happens even before manager state is updated in the next - * few lines causing the internal event handler to miss */ - - /* Set Wi-Fi storage again to flash to keep the newly - * provided credentials on NVS */ - if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK) { - ESP_LOGE(TAG, "Failed to set storage Wi-Fi"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - /* Configure Wi-Fi station with host credentials - * provided during provisioning */ - if (esp_wifi_set_config(WIFI_IF_STA, wifi_cfg) != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi configuration"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - /* Connect to AP after one second so that the response can - * be sent to the client successfully, before a channel change happens*/ - if (esp_timer_start_once(prov_ctx->wifi_connect_timer, 1000 * 1000U) != ESP_OK) { - ESP_LOGE(TAG, "Failed to start Wi-Fi connect timer"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_FAIL; - } - - /* Reset Wi-Fi station state for provisioning app */ - prov_ctx->wifi_state = WIFI_PROV_STA_CONNECTING; - prov_ctx->prov_state = WIFI_PROV_STATE_CRED_RECV; - /* Execute user registered callback handler */ - execute_event_cb(WIFI_PROV_CRED_RECV, (void *)&wifi_cfg->sta, sizeof(wifi_cfg->sta)); - RELEASE_LOCK(prov_ctx_lock); - - return ESP_OK; -} - -esp_err_t wifi_prov_mgr_init(wifi_prov_mgr_config_t config) -{ - if (!prov_ctx_lock) { - /* Create mutex if this is the first time init is being called. - * This is created only once and never deleted because if some - * other thread is trying to take this mutex while it is being - * deleted from another thread then the reference may become - * invalid and cause exception */ - prov_ctx_lock = xSemaphoreCreateMutex(); - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Failed to create mutex"); - return ESP_ERR_NO_MEM; - } - } - - void *fn_ptrs[] = { - config.scheme.prov_stop, - config.scheme.prov_start, - config.scheme.new_config, - config.scheme.delete_config, - config.scheme.set_config_service, - config.scheme.set_config_endpoint - }; - - /* All function pointers in the scheme structure must be non-null */ - for (size_t i = 0; i < sizeof(fn_ptrs)/sizeof(fn_ptrs[0]); i++) { - if (!fn_ptrs[i]) { - return ESP_ERR_INVALID_ARG; - } - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx) { - ESP_LOGE(TAG, "Provisioning manager already initialized"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_ERR_INVALID_STATE; - } - - /* Allocate memory for provisioning app data */ - prov_ctx = (struct wifi_prov_mgr_ctx *) calloc(1, sizeof(struct wifi_prov_mgr_ctx)); - if (!prov_ctx) { - ESP_LOGE(TAG, "Error allocating memory for singleton instance"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_ERR_NO_MEM; - } - - prov_ctx->mgr_config = config; - prov_ctx->prov_state = WIFI_PROV_STATE_IDLE; - prov_ctx->mgr_info.version = WIFI_PROV_MGR_VERSION; - - /* Allocate memory for provisioning scheme configuration */ - const wifi_prov_scheme_t *scheme = &prov_ctx->mgr_config.scheme; - esp_err_t ret = ESP_OK; - prov_ctx->prov_scheme_config = scheme->new_config(); - if (!prov_ctx->prov_scheme_config) { - ESP_LOGE(TAG, "failed to allocate provisioning scheme configuration"); - ret = ESP_ERR_NO_MEM; - goto exit; - } - - ret = scheme->set_config_endpoint(prov_ctx->prov_scheme_config, "prov-ctrl", 0xFF4F); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to configure Wi-Fi state control endpoint"); - goto exit; - } - - ret = scheme->set_config_endpoint(prov_ctx->prov_scheme_config, "prov-scan", 0xFF50); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to configure Wi-Fi scanning endpoint"); - goto exit; - } - - ret = scheme->set_config_endpoint(prov_ctx->prov_scheme_config, "prov-session", 0xFF51); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to configure security endpoint"); - goto exit; - } - - ret = scheme->set_config_endpoint(prov_ctx->prov_scheme_config, "prov-config", 0xFF52); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to configure Wi-Fi configuration endpoint"); - goto exit; - } - - ret = scheme->set_config_endpoint(prov_ctx->prov_scheme_config, "proto-ver", 0xFF53); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to configure version endpoint"); - goto exit; - } - - /* Application specific custom endpoints will be assigned - * incremental UUIDs starting after this value */ - prov_ctx->endpoint_uuid_used = 0xFF53; - - /* This delay is so that the client side app is notified first - * and then the provisioning is stopped. Default is 1000ms. */ - prov_ctx->cleanup_delay = 1000; - -exit: - if (ret != ESP_OK) { - if (prov_ctx->prov_scheme_config) { - config.scheme.delete_config(prov_ctx->prov_scheme_config); - } - free(prov_ctx); - } else { - execute_event_cb(WIFI_PROV_INIT, NULL, 0); - } - RELEASE_LOCK(prov_ctx_lock); - return ret; -} - -void wifi_prov_mgr_wait(void) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return; - } - - while (1) { - ACQUIRE_LOCK(prov_ctx_lock); - if (prov_ctx && - prov_ctx->prov_state != WIFI_PROV_STATE_IDLE) { - RELEASE_LOCK(prov_ctx_lock); - vTaskDelay(1000 / portTICK_PERIOD_MS); - continue; - } - break; - } - RELEASE_LOCK(prov_ctx_lock); -} - -void wifi_prov_mgr_deinit(void) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return; - } - - ACQUIRE_LOCK(prov_ctx_lock); - - /* This will do one of these: - * 1) if found running, stop the provisioning service (returns true) - * 2) if service was already in the process of termination, this will - * wait till the service is stopped (returns false) - * 3) if service was not running, this will return immediately (returns false) - */ - bool service_was_running = wifi_prov_mgr_stop_service(1); - - /* If service was not running, its also possible that manager - * was not even initialized */ - if (!service_was_running && !prov_ctx) { - ESP_LOGD(TAG, "Manager already de-initialized"); - RELEASE_LOCK(prov_ctx_lock); - vSemaphoreDelete(prov_ctx_lock); - prov_ctx_lock = NULL; - return; - } - - if (prov_ctx->app_info_json) { - cJSON_Delete(prov_ctx->app_info_json); - } - - if (prov_ctx->prov_scheme_config) { - prov_ctx->mgr_config.scheme.delete_config(prov_ctx->prov_scheme_config); - } - - /* Extract the callbacks to be called post deinit */ - wifi_prov_cb_func_t app_cb = prov_ctx->mgr_config.app_event_handler.event_cb; - void *app_data = prov_ctx->mgr_config.app_event_handler.user_data; - - wifi_prov_cb_func_t scheme_cb = prov_ctx->mgr_config.scheme_event_handler.event_cb; - void *scheme_data = prov_ctx->mgr_config.scheme_event_handler.user_data; - - /* Free manager context */ - free(prov_ctx); - prov_ctx = NULL; - RELEASE_LOCK(prov_ctx_lock); - - /* If a running service was also stopped during de-initialization - * then WIFI_PROV_END event also needs to be emitted before deinit */ - if (service_was_running) { - ESP_LOGD(TAG, "execute_event_cb : %d", WIFI_PROV_END); - if (scheme_cb) { - scheme_cb(scheme_data, WIFI_PROV_END, NULL); - } - if (app_cb) { - app_cb(app_data, WIFI_PROV_END, NULL); - } - if (esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_END, NULL, 0, portMAX_DELAY) != ESP_OK) { - ESP_LOGE(TAG, "Failed to post event WIFI_PROV_END"); - } - } - - ESP_LOGD(TAG, "execute_event_cb : %d", WIFI_PROV_DEINIT); - - /* Execute deinit event callbacks */ - if (scheme_cb) { - scheme_cb(scheme_data, WIFI_PROV_DEINIT, NULL); - } - if (app_cb) { - app_cb(app_data, WIFI_PROV_DEINIT, NULL); - } - if (esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_DEINIT, NULL, 0, portMAX_DELAY) != ESP_OK) { - ESP_LOGE(TAG, "Failed to post event WIFI_PROV_DEINIT"); - } - - vSemaphoreDelete(prov_ctx_lock); - prov_ctx_lock = NULL; -} - -esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const void *wifi_prov_sec_params, - const char *service_name, const char *service_key) -{ - uint8_t restore_wifi_flag = 0; - - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - ACQUIRE_LOCK(prov_ctx_lock); - if (!prov_ctx) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_ERR_INVALID_STATE; - } - - if (prov_ctx->prov_state != WIFI_PROV_STATE_IDLE) { - ESP_LOGE(TAG, "Provisioning service already started"); - RELEASE_LOCK(prov_ctx_lock); - return ESP_ERR_INVALID_STATE; - } - - esp_err_t ret = ESP_OK; - /* Update state so that parallel call to wifi_prov_mgr_start_provisioning() - * or wifi_prov_mgr_stop_provisioning() or wifi_prov_mgr_deinit() from another - * thread doesn't interfere with this process */ - prov_ctx->prov_state = WIFI_PROV_STATE_STARTING; - - /* Start Wi-Fi in Station Mode. - * This is necessary for scanning to work */ - ret = esp_wifi_set_mode(WIFI_MODE_STA); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi mode to STA"); - goto err; - } - ret = esp_wifi_start(); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to start Wi-Fi"); - goto err; - } - - /* Change Wi-Fi storage to RAM temporarily and erase any old - * credentials in RAM(i.e. without erasing the copy on NVS). Also - * call disconnect to make sure device doesn't remain connected - * to the AP whose credentials were present earlier */ - wifi_config_t wifi_cfg_empty, wifi_cfg_old; - memset(&wifi_cfg_empty, 0, sizeof(wifi_config_t)); - esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg_old); - ret = esp_wifi_set_storage(WIFI_STORAGE_RAM); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi storage to RAM"); - goto err; - } - - /* WiFi storage needs to be restored before exiting this API */ - restore_wifi_flag |= WIFI_PROV_STORAGE_BIT; - /* Erase Wi-Fi credentials in RAM, when call disconnect and user code - * receive WIFI_EVENT_STA_DISCONNECTED and maybe call esp_wifi_connect, at - * this time Wi-Fi will have no configuration to connect */ - ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg_empty); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set empty Wi-Fi credentials"); - goto err; - } - /* WiFi settings needs to be restored if provisioning error before exiting this API */ - restore_wifi_flag |= WIFI_PROV_SETTING_BIT; - - ret = esp_wifi_disconnect(); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to disconnect"); - goto err; - } - -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_0 - /* Initialize app data */ - if (security == WIFI_PROV_SECURITY_0) { - prov_ctx->mgr_info.capabilities.no_sec = true; - } -#endif -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1 - if (security == WIFI_PROV_SECURITY_1) { - if (wifi_prov_sec_params) { - static protocomm_security1_params_t sec1_params; - // Generate internal copy of "pop", that shall be freed at the end - char *pop = strdup(wifi_prov_sec_params); - if (pop == NULL) { - ESP_LOGE(TAG, "Failed to allocate memory for pop"); - ret = ESP_ERR_NO_MEM; - goto err; - } - sec1_params.data = (const uint8_t *)pop; - sec1_params.len = strlen(pop); - prov_ctx->protocomm_sec_params = (const void *) &sec1_params; - } else { - prov_ctx->mgr_info.capabilities.no_pop = true; - } - } -#endif -#ifdef CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2 - if (security == WIFI_PROV_SECURITY_2) { - if (wifi_prov_sec_params) { - prov_ctx->protocomm_sec_params = wifi_prov_sec_params; - } - } -#endif - prov_ctx->security = security; - - - esp_timer_create_args_t wifi_connect_timer_conf = { - .callback = wifi_connect_timer_cb, - .arg = NULL, - .dispatch_method = ESP_TIMER_TASK, - .name = "wifi_prov_connect_tm" - }; - ret = esp_timer_create(&wifi_connect_timer_conf, &prov_ctx->wifi_connect_timer); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to create Wi-Fi connect timer"); - goto err; - } - - /* If auto stop on completion is enabled (default) create the stopping timer */ - if (!prov_ctx->mgr_info.capabilities.no_auto_stop) { - /* Create timer object as a member of app data */ - esp_timer_create_args_t autostop_timer_conf = { - .callback = stop_prov_timer_cb, - .arg = NULL, - .dispatch_method = ESP_TIMER_TASK, - .name = "wifi_prov_autostop_tm" - }; - ret = esp_timer_create(&autostop_timer_conf, &prov_ctx->autostop_timer); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to create auto-stop timer"); - esp_timer_delete(prov_ctx->wifi_connect_timer); - goto err; - } - } - - esp_timer_create_args_t cleanup_delay_timer = { - .callback = cleanup_delay_timer_cb, - .arg = NULL, - .dispatch_method = ESP_TIMER_TASK, - .name = "cleanup_delay_tm" - }; - ret = esp_timer_create(&cleanup_delay_timer, &prov_ctx->cleanup_delay_timer); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to create cleanup delay timer"); - esp_timer_delete(prov_ctx->wifi_connect_timer); - esp_timer_delete(prov_ctx->autostop_timer); - goto err; - } - - - /* System APIs for BLE / Wi-Fi will be called inside wifi_prov_mgr_start_service(), - * which may trigger system level events. Hence, releasing the context lock will - * ensure that wifi_prov_mgr_event_handler() doesn't block the global event_loop - * handler when system events need to be handled */ - RELEASE_LOCK(prov_ctx_lock); - - /* Start provisioning service */ - ret = wifi_prov_mgr_start_service(service_name, service_key); - if (ret != ESP_OK) { - esp_timer_delete(prov_ctx->autostop_timer); - esp_timer_delete(prov_ctx->wifi_connect_timer); - esp_timer_delete(prov_ctx->cleanup_delay_timer); - } - ACQUIRE_LOCK(prov_ctx_lock); - if (ret == ESP_OK) { - prov_ctx->prov_state = WIFI_PROV_STATE_STARTED; - /* Execute user registered callback handler */ - execute_event_cb(WIFI_PROV_START, NULL, 0); - goto exit; - } - -err: - prov_ctx->prov_state = WIFI_PROV_STATE_IDLE; - if (restore_wifi_flag & WIFI_PROV_SETTING_BIT) { - /* Restore current WiFi settings, since provisioning start has failed */ - esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg_old); - } -exit: - if (restore_wifi_flag & WIFI_PROV_STORAGE_BIT) { - /* Restore WiFi storage back to FLASH */ - esp_wifi_set_storage(WIFI_STORAGE_FLASH); - } - RELEASE_LOCK(prov_ctx_lock); - return ret; -} - -void wifi_prov_mgr_stop_provisioning(void) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return; - } - - ACQUIRE_LOCK(prov_ctx_lock); - - /* Launches task for stopping the provisioning service. This will do one of these: - * 1) start a task for stopping the provisioning service (returns true) - * 2) if service was already in the process of termination, this will - * wait till the service is stopped (returns false) - * 3) if service was not running, this will return immediately (returns false) - */ - wifi_prov_mgr_stop_service(0); - - RELEASE_LOCK(prov_ctx_lock); -} - -esp_err_t wifi_prov_mgr_reset_provisioning(void) -{ - esp_err_t ret = esp_wifi_restore(); - - if (ret != ESP_OK) { - ESP_LOGE(TAG, "esp_wifi_restore fail, ret is %d", ret); - ret = ESP_FAIL; - } - - return ret; -} - -esp_err_t wifi_prov_mgr_reset_sm_state_on_failure(void) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - ACQUIRE_LOCK(prov_ctx_lock); - - esp_err_t err = ESP_OK; - if (prov_ctx->prov_state != WIFI_PROV_STATE_FAIL) { - ESP_LOGE(TAG, "Trying reset when not in failure state. Current state: %d", prov_ctx->prov_state); - err = ESP_ERR_INVALID_STATE; - goto exit; - } - - wifi_config_t wifi_cfg = {0}; - - err = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to set wifi config, 0x%x", err); - goto exit; - } - - prov_ctx->prov_state = WIFI_PROV_STATE_STARTED; - -exit: - RELEASE_LOCK(prov_ctx_lock); - return err; -} - -esp_err_t wifi_prov_mgr_reset_sm_state_for_reprovision(void) -{ - if (!prov_ctx_lock) { - ESP_LOGE(TAG, "Provisioning manager not initialized"); - return ESP_ERR_INVALID_STATE; - } - - ACQUIRE_LOCK(prov_ctx_lock); - - esp_err_t ret = ESP_OK; - wifi_config_t wifi_cfg_empty = {0}; - uint8_t restore_wifi_flag = 0; - - if (!prov_ctx->mgr_info.capabilities.no_auto_stop) { - ESP_LOGE(TAG, "Execute wifi_prov_mgr_disable_auto_stop() before calling this API"); - ret = ESP_ERR_INVALID_STATE; - goto exit; - } - - ret = esp_wifi_set_storage(WIFI_STORAGE_RAM); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi storage to RAM"); - goto exit; - } - restore_wifi_flag |= WIFI_PROV_STORAGE_BIT; - - ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg_empty); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to set empty Wi-Fi credentials, 0x%x", ret); - goto exit; - } - - ret = esp_wifi_disconnect(); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to disconnect wifi, 0x%x", ret); - goto exit; - } - - prov_ctx->prov_state = WIFI_PROV_STATE_STARTED; - execute_event_cb(WIFI_PROV_START, NULL, 0); - -exit: - if (restore_wifi_flag & WIFI_PROV_STORAGE_BIT) { - esp_wifi_set_storage(WIFI_STORAGE_FLASH); - } - RELEASE_LOCK(prov_ctx_lock); - return ret; -} diff --git a/components/wifi_provisioning/src/scheme_ble.c b/components/wifi_provisioning/src/scheme_ble.c deleted file mode 100644 index f1240fbaea96..000000000000 --- a/components/wifi_provisioning/src/scheme_ble.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#ifdef CONFIG_BT_CONTROLLER_ENABLED -#include "esp_bt.h" -#endif - -#include -#include - -#include "wifi_provisioning/scheme_ble.h" -#include "wifi_provisioning_priv.h" - -static const char *TAG = "wifi_prov_scheme_ble"; - -extern const wifi_prov_scheme_t wifi_prov_scheme_ble; - -static uint8_t *custom_service_uuid; -static uint8_t *custom_ble_addr; -static uint8_t *custom_manufacturer_data; -static size_t custom_manufacturer_data_len; - -static esp_err_t prov_start(protocomm_t *pc, void *config) -{ - if (!pc) { - ESP_LOGE(TAG, "Protocomm handle cannot be null"); - return ESP_ERR_INVALID_ARG; - } - - if (!config) { - ESP_LOGE(TAG, "Cannot start with null configuration"); - return ESP_ERR_INVALID_ARG; - } - - protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config; - -#if defined(CONFIG_WIFI_PROV_BLE_BONDING) - ble_config->ble_bonding = 1; -#endif - -#if defined(CONFIG_WIFI_PROV_BLE_SEC_CONN) || defined(CONFIG_BT_BLUEDROID_ENABLED) - ble_config->ble_sm_sc = 1; -#endif - -#if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION) - ble_config->ble_link_encryption = 1; -#endif - /* Start protocomm as BLE service */ - if (protocomm_ble_start(pc, ble_config) != ESP_OK) { - ESP_LOGE(TAG, "Failed to start protocomm BLE service"); - return ESP_FAIL; - } - return ESP_OK; -} - -esp_err_t wifi_prov_scheme_ble_set_random_addr(const uint8_t *addr) -{ - if (!addr) { - return ESP_ERR_INVALID_ARG; - } - - custom_ble_addr = (uint8_t *) malloc(BLE_ADDR_LEN); - if (custom_ble_addr == NULL) { - ESP_LOGE(TAG, "Error allocating memory for random address"); - return ESP_ERR_NO_MEM; - } - - memcpy(custom_ble_addr, addr, BLE_ADDR_LEN); - return ESP_OK; -} - -esp_err_t wifi_prov_scheme_ble_set_service_uuid(uint8_t *uuid128) -{ - if (!uuid128) { - return ESP_ERR_INVALID_ARG; - } - custom_service_uuid = uuid128; - return ESP_OK; -} - -esp_err_t wifi_prov_scheme_ble_set_mfg_data(uint8_t *mfg_data, ssize_t mfg_data_len) -{ - if (!mfg_data || !mfg_data_len) { - return ESP_ERR_INVALID_ARG; - } - - custom_manufacturer_data = (uint8_t *) malloc(mfg_data_len); - if (custom_manufacturer_data == NULL) { - ESP_LOGE(TAG, "Error allocating memory for mfg_data"); - return ESP_ERR_NO_MEM; - } - - custom_manufacturer_data_len = mfg_data_len; - memcpy(custom_manufacturer_data, mfg_data, mfg_data_len); - return ESP_OK; -} - -static void *new_config(void) -{ - protocomm_ble_config_t *ble_config = calloc(1, sizeof(protocomm_ble_config_t)); - if (!ble_config) { - ESP_LOGE(TAG, "Error allocating memory for new configuration"); - return NULL; - } - - /* The default provisioning service UUID */ - const uint8_t service_uuid[16] = { - /* LSB <--------------------------------------- - * ---------------------------------------> MSB */ - 0x07, 0xed, 0x9b, 0x2d, 0x0f, 0x06, 0x7c, 0x87, - 0x9b, 0x43, 0x43, 0x6b, 0x4d, 0x24, 0x75, 0x17, - }; - - memcpy(ble_config->service_uuid, service_uuid, sizeof(ble_config->service_uuid)); - return ble_config; -} - -static void delete_config(void *config) -{ - if (!config) { - ESP_LOGE(TAG, "Cannot delete null configuration"); - return; - } - - protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config; - for (unsigned int i = 0; i < ble_config->nu_lookup_count; i++) { - free((void *)ble_config->nu_lookup[i].name); - } - free(ble_config->nu_lookup); - free(ble_config); -} - -static esp_err_t set_config_service(void *config, const char *service_name, const char *service_key) -{ - if (!config) { - ESP_LOGE(TAG, "Cannot set null configuration"); - return ESP_ERR_INVALID_ARG; - } - - if (!service_name) { - ESP_LOGE(TAG, "Service name cannot be NULL"); - return ESP_ERR_INVALID_ARG; - } - - protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config; - strlcpy(ble_config->device_name, service_name, sizeof(ble_config->device_name)); - - /* If a custom service UUID has been provided, override the default one */ - if (custom_service_uuid) { - memcpy(ble_config->service_uuid, custom_service_uuid, sizeof(ble_config->service_uuid)); - } - /* Set manufacturer data if it is provided by app */ - if (custom_manufacturer_data) { - size_t mfg_data_len = custom_manufacturer_data_len; - /* Manufacturer Data Length + 2 Byte header + BLE Device name + 2 Byte - * header <= 31 Bytes */ - if (mfg_data_len > (MAX_BLE_MANUFACTURER_DATA_LEN - sizeof(ble_config->device_name) - 2)) { - ESP_LOGE(TAG, "Manufacturer data length is more than the max allowed size; expect truncated mfg_data "); - /* XXX Does it even make any sense to set truncated mfg_data ? The - * only reason to not return failure from here is provisioning - * should continue as it is with error prints for mfg_data length */ - mfg_data_len = MAX_BLE_MANUFACTURER_DATA_LEN - sizeof(ble_config->device_name) - 2; - } - - ble_config->manufacturer_data = custom_manufacturer_data; - ble_config->manufacturer_data_len = mfg_data_len; - } else { - ble_config->manufacturer_data = NULL; - ble_config->manufacturer_data_len = 0; - } - - if (custom_ble_addr){ - ble_config->ble_addr = custom_ble_addr; - } else { - ble_config->ble_addr = NULL; - } - - return ESP_OK; -} - -static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, uint16_t uuid) -{ - if (!config) { - ESP_LOGE(TAG, "Cannot set null configuration"); - return ESP_ERR_INVALID_ARG; - } - - if (!endpoint_name) { - ESP_LOGE(TAG, "EP name cannot be null"); - return ESP_ERR_INVALID_ARG; - } - - protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config; - - char *copy_ep_name = strdup(endpoint_name); - if (!copy_ep_name) { - ESP_LOGE(TAG, "Error allocating memory for EP name"); - return ESP_ERR_NO_MEM; - } - - protocomm_ble_name_uuid_t *lookup_table = ( - realloc(ble_config->nu_lookup, (ble_config->nu_lookup_count + 1) * sizeof(protocomm_ble_name_uuid_t))); - if (!lookup_table) { - ESP_LOGE(TAG, "Error allocating memory for EP-UUID lookup table"); - return ESP_ERR_NO_MEM; - } - - lookup_table[ble_config->nu_lookup_count].name = copy_ep_name; - lookup_table[ble_config->nu_lookup_count].uuid = uuid; - ble_config->nu_lookup = lookup_table; - ble_config->nu_lookup_count += 1; - return ESP_OK; -} - -/* Used when both BT and BLE are not needed by application */ -void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event_t event, void *event_data) -{ - switch (event) { - case WIFI_PROV_INIT: -#ifdef CONFIG_BT_CONTROLLER_ENABLED - esp_err_t err; - /* Release BT memory, as we need only BLE */ - err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of classic BT failed %d", err); - } else { - ESP_LOGI(TAG, "BT memory released"); - } -#endif - break; - - case WIFI_PROV_DEINIT: -#ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV -#ifdef CONFIG_BT_CONTROLLER_ENABLED - /* Release memory used by BLE and Bluedroid host stack */ - err = esp_bt_mem_release(ESP_BT_MODE_BTDM); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of BTDM failed %d", err); - } else { - ESP_LOGI(TAG, "BTDM memory released"); - } -#endif -#endif - break; - - default: - break; - } -} - -/* Used when BT is not needed by application */ -void wifi_prov_scheme_ble_event_cb_free_bt(void *user_data, wifi_prov_cb_event_t event, void *event_data) -{ - switch (event) { - case WIFI_PROV_INIT: -#ifdef CONFIG_BT_CONTROLLER_ENABLED - esp_err_t err; - /* Release BT memory, as we need only BLE */ - err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of classic BT failed %d", err); - } else { - ESP_LOGI(TAG, "BT memory released"); - } -#endif - break; - - default: - break; - } -} - -/* Used when BLE is not needed by application */ -void wifi_prov_scheme_ble_event_cb_free_ble(void *user_data, wifi_prov_cb_event_t event, void *event_data) -{ - switch (event) { - case WIFI_PROV_DEINIT: -#ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV -#ifdef CONFIG_BT_CONTROLLER_ENABLED - esp_err_t err; - /* Release memory used by BLE stack */ - err = esp_bt_mem_release(ESP_BT_MODE_BLE); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of BLE failed %d", err); - } else { - ESP_LOGI(TAG, "BLE memory released"); - } -#endif -#endif - break; - - default: - break; - } -} - -const wifi_prov_scheme_t wifi_prov_scheme_ble = { - .prov_start = prov_start, - .prov_stop = protocomm_ble_stop, - .new_config = new_config, - .delete_config = delete_config, - .set_config_service = set_config_service, - .set_config_endpoint = set_config_endpoint, - .wifi_mode = WIFI_MODE_STA -}; diff --git a/components/wifi_provisioning/src/scheme_console.c b/components/wifi_provisioning/src/scheme_console.c deleted file mode 100644 index 28732847acdd..000000000000 --- a/components/wifi_provisioning/src/scheme_console.c +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include - -#include -#include - -#include "wifi_provisioning/scheme_console.h" -#include "wifi_provisioning_priv.h" - -static const char *TAG = "wifi_prov_scheme_console"; - -extern const wifi_prov_scheme_t wifi_prov_scheme_console; - -static esp_err_t prov_start(protocomm_t *pc, void *config) -{ - if (!pc) { - ESP_LOGE(TAG, "Protocomm handle cannot be null"); - return ESP_ERR_INVALID_ARG; - } - - if (!config) { - ESP_LOGE(TAG, "Cannot start with null configuration"); - return ESP_ERR_INVALID_ARG; - } - - protocomm_console_config_t *console_config = (protocomm_console_config_t *) config; - - /* Start protocomm console */ - esp_err_t err = protocomm_console_start(pc, console_config); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to start protocomm HTTP server"); - return ESP_FAIL; - } - return ESP_OK; -} - -static void *new_config(void) -{ - protocomm_console_config_t *console_config = malloc(sizeof(protocomm_console_config_t)); - if (!console_config) { - ESP_LOGE(TAG, "Error allocating memory for new configuration"); - return NULL; - } - protocomm_console_config_t default_config = PROTOCOMM_CONSOLE_DEFAULT_CONFIG(); - memcpy(console_config, &default_config, sizeof(default_config)); - return console_config; -} - -static void delete_config(void *config) -{ - if (!config) { - ESP_LOGE(TAG, "Cannot delete null configuration"); - return; - } - free(config); -} - -static esp_err_t set_config_service(void *config, const char *service_name, const char *service_key) -{ - return ESP_OK; -} - -static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, uint16_t uuid) -{ - return ESP_OK; -} - -const wifi_prov_scheme_t wifi_prov_scheme_console = { - .prov_start = prov_start, - .prov_stop = protocomm_console_stop, - .new_config = new_config, - .delete_config = delete_config, - .set_config_service = set_config_service, - .set_config_endpoint = set_config_endpoint, - .wifi_mode = WIFI_MODE_STA -}; diff --git a/components/wifi_provisioning/src/scheme_softap.c b/components/wifi_provisioning/src/scheme_softap.c deleted file mode 100644 index 5c460c3280d0..000000000000 --- a/components/wifi_provisioning/src/scheme_softap.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "sdkconfig.h" - -#include -#include -#include -#include - -#include -#include - -#include "wifi_provisioning/scheme_softap.h" -#include "wifi_provisioning_priv.h" - -typedef struct softap_config { - protocomm_httpd_config_t httpd_config; - char ssid[33]; - char password[65]; -} wifi_prov_softap_config_t; - -static const char *TAG = "wifi_prov_scheme_softap"; - -extern const wifi_prov_scheme_t wifi_prov_scheme_softap; -static void *scheme_softap_prov_httpd_handle; -static esp_err_t start_wifi_ap(const char *ssid, const char *pass) -{ - /* Build Wi-Fi configuration for AP mode */ - wifi_config_t wifi_config = { - .ap = { - .max_connection = 5, - }, - }; - - /* SSID can be a non NULL terminated string if `ap.ssid_len` is specified - * Hence, memcpy is used to support 32 bytes long SSID per 802.11 standard */ - const size_t ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid)); - memcpy(wifi_config.ap.ssid, ssid, ssid_len); - wifi_config.ap.ssid_len = ssid_len; - - if (strlen(pass) == 0) { - memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password)); - wifi_config.ap.authmode = WIFI_AUTH_OPEN; - } else { - strlcpy((char *) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password)); - wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK; - } - - /* Run Wi-Fi in AP + STA mode with configuration built above */ - esp_err_t err = esp_wifi_set_mode(WIFI_MODE_APSTA); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi mode : %d", err); - return err; - } - err = esp_wifi_set_config(WIFI_IF_AP, &wifi_config); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to set Wi-Fi config : %d", err); - return err; - } - - return ESP_OK; -} - -static esp_err_t prov_start(protocomm_t *pc, void *config) -{ - if (!pc) { - ESP_LOGE(TAG, "Protocomm handle cannot be null"); - return ESP_ERR_INVALID_ARG; - } - - if (!config) { - ESP_LOGE(TAG, "Cannot start with null configuration"); - return ESP_ERR_INVALID_ARG; - } - - wifi_prov_softap_config_t *softap_config = (wifi_prov_softap_config_t *) config; - - protocomm_httpd_config_t *httpd_config = &softap_config->httpd_config; - - if (scheme_softap_prov_httpd_handle) { - httpd_config->ext_handle_provided = true; - httpd_config->data.handle = scheme_softap_prov_httpd_handle; - } - - /* Start protocomm server on top of HTTP */ - esp_err_t err = protocomm_httpd_start(pc, httpd_config); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to start protocomm HTTP server"); - return err; - } - - /* Start Wi-Fi softAP with specified ssid and password */ - err = start_wifi_ap(softap_config->ssid, softap_config->password); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to start Wi-Fi AP"); - protocomm_httpd_stop(pc); - return err; - } - - return ESP_OK; -} - -static esp_err_t prov_stop(protocomm_t *pc) -{ - esp_err_t err = protocomm_httpd_stop(pc); - if (err != ESP_OK) { - ESP_LOGW(TAG, "Error occurred while stopping protocomm_httpd"); - } - - return err; -} - -static void *new_config(void) -{ - wifi_prov_softap_config_t *softap_config = calloc(1, sizeof(wifi_prov_softap_config_t)); - if (!softap_config) { - ESP_LOGE(TAG, "Error allocating memory for new configuration"); - return NULL; - } - protocomm_httpd_config_t default_config = { - .data = { - .config = PROTOCOMM_HTTPD_DEFAULT_CONFIG() - } - }; - softap_config->httpd_config = default_config; - return softap_config; -} - -static void delete_config(void *config) -{ - if (!config) { - ESP_LOGE(TAG, "Cannot delete null configuration"); - return; - } - - wifi_prov_softap_config_t *softap_config = (wifi_prov_softap_config_t *) config; - free(softap_config); -} - -static esp_err_t set_config_service(void *config, const char *service_name, const char *service_key) -{ - if (!config) { - ESP_LOGE(TAG, "Cannot set null configuration"); - return ESP_ERR_INVALID_ARG; - } - - if (!service_name) { - ESP_LOGE(TAG, "Service name cannot be NULL"); - return ESP_ERR_INVALID_ARG; - } - - wifi_prov_softap_config_t *softap_config = (wifi_prov_softap_config_t *) config; - if (service_key) { - const int service_key_len = strlen(service_key); - if (service_key_len < 8 || service_key_len >= sizeof(softap_config->password)) { - ESP_LOGE(TAG, "Incorrect passphrase length for softAP: %d (Expected: Min - 8, Max - 64)", service_key_len); - return ESP_ERR_INVALID_ARG; - } - strlcpy(softap_config->password, service_key, sizeof(softap_config->password)); - } - strlcpy(softap_config->ssid, service_name, sizeof(softap_config->ssid)); - return ESP_OK; -} - -static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, uint16_t uuid) -{ - return ESP_OK; -} - -void wifi_prov_scheme_softap_set_httpd_handle(void *handle) -{ - scheme_softap_prov_httpd_handle = handle; -} - -const wifi_prov_scheme_t wifi_prov_scheme_softap = { - .prov_start = prov_start, - .prov_stop = prov_stop, - .new_config = new_config, - .delete_config = delete_config, - .set_config_service = set_config_service, - .set_config_endpoint = set_config_endpoint, - .wifi_mode = WIFI_MODE_APSTA -}; diff --git a/components/wifi_provisioning/src/wifi_config.c b/components/wifi_provisioning/src/wifi_config.c deleted file mode 100644 index 1075a3180899..000000000000 --- a/components/wifi_provisioning/src/wifi_config.c +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include - -#include "wifi_constants.pb-c.h" -#include "wifi_config.pb-c.h" - -#include - -static const char* TAG = "WiFiProvConfig"; - -typedef struct wifi_prov_config_cmd { - int cmd_num; - esp_err_t (*command_handler)(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data); -} wifi_prov_config_cmd_t; - -static esp_err_t cmd_get_status_handler(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data); - -static esp_err_t cmd_set_config_handler(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data); - -static esp_err_t cmd_apply_config_handler(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data); - -static wifi_prov_config_cmd_t cmd_table[] = { - { - .cmd_num = WI_FI_CONFIG_MSG_TYPE__TypeCmdGetStatus, - .command_handler = cmd_get_status_handler - }, - { - .cmd_num = WI_FI_CONFIG_MSG_TYPE__TypeCmdSetConfig, - .command_handler = cmd_set_config_handler - }, - { - .cmd_num = WI_FI_CONFIG_MSG_TYPE__TypeCmdApplyConfig, - .command_handler = cmd_apply_config_handler - } -}; - -static esp_err_t cmd_get_status_handler(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data) -{ - ESP_LOGD(TAG, "Enter cmd_get_status_handler"); - wifi_prov_config_handlers_t *h = (wifi_prov_config_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespGetStatus *resp_payload = (RespGetStatus *) malloc(sizeof(RespGetStatus)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - resp_get_status__init(resp_payload); - - wifi_prov_config_get_data_t resp_data; - if (h->get_status_handler(&resp_data, &h->ctx) == ESP_OK) { - if (resp_data.wifi_state == WIFI_PROV_STA_CONNECTING) { - resp_payload->sta_state = WIFI_STATION_STATE__Connecting; - resp_payload->state_case = RESP_GET_STATUS__STATE_CONNECTED; - } else if (resp_data.wifi_state == WIFI_PROV_STA_CONNECTED) { - resp_payload->sta_state = WIFI_STATION_STATE__Connected; - resp_payload->state_case = RESP_GET_STATUS__STATE_CONNECTED; - WifiConnectedState *connected = (WifiConnectedState *)( - malloc(sizeof(WifiConnectedState))); - if (!connected) { - free(resp_payload); - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - resp_payload->connected = connected; - wifi_connected_state__init(connected); - - connected->ip4_addr = strdup(resp_data.conn_info.ip_addr); - if (connected->ip4_addr == NULL) { - free(resp_payload); - return ESP_ERR_NO_MEM; - } - - connected->bssid.len = sizeof(resp_data.conn_info.bssid); - connected->bssid.data = (uint8_t *) strndup(resp_data.conn_info.bssid, - sizeof(resp_data.conn_info.bssid)); - if (connected->bssid.data == NULL) { - free(connected->ip4_addr); - free(resp_payload); - return ESP_ERR_NO_MEM; - } - - connected->ssid.len = strlen(resp_data.conn_info.ssid); - connected->ssid.data = (uint8_t *) strdup(resp_data.conn_info.ssid); - if (connected->ssid.data == NULL) { - free(connected->bssid.data); - free(connected->ip4_addr); - free(resp_payload); - return ESP_ERR_NO_MEM; - } - - connected->channel = resp_data.conn_info.channel; - connected->auth_mode = resp_data.conn_info.auth_mode; - } else if (resp_data.wifi_state == WIFI_PROV_STA_DISCONNECTED) { - resp_payload->sta_state = WIFI_STATION_STATE__ConnectionFailed; - resp_payload->state_case = RESP_GET_STATUS__STATE_FAIL_REASON; - - if (resp_data.fail_reason == WIFI_PROV_STA_AUTH_ERROR) { - resp_payload->fail_reason = WIFI_CONNECT_FAILED_REASON__AuthError; - } else if (resp_data.fail_reason == WIFI_PROV_STA_AP_NOT_FOUND) { - resp_payload->fail_reason = WIFI_CONNECT_FAILED_REASON__NetworkNotFound; - } - } - resp_payload->status = STATUS__Success; - } - - resp->payload_case = WI_FI_CONFIG_PAYLOAD__PAYLOAD_RESP_GET_STATUS; - resp->resp_get_status = resp_payload; - return ESP_OK; -} - -static esp_err_t cmd_set_config_handler(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data) -{ - ESP_LOGD(TAG, "Enter cmd_set_config_handler"); - wifi_prov_config_handlers_t *h = (wifi_prov_config_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespSetConfig *resp_payload = (RespSetConfig *) malloc(sizeof(RespSetConfig)); - if (resp_payload == NULL) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - resp_set_config__init(resp_payload); - - wifi_prov_config_set_data_t req_data; - memset(&req_data, 0, sizeof(req_data)); - - /* Check arguments provided in protobuf packet: - * - SSID / Passphrase string length must be within the standard limits - * - BSSID must either be NULL or have length equal to that imposed by the standard - * If any of these conditions are not satisfied, don't invoke the handler and - * send error status without closing connection */ - resp_payload->status = STATUS__InvalidArgument; - if (req->cmd_set_config->bssid.len != 0 && - req->cmd_set_config->bssid.len != sizeof(req_data.bssid)) { - ESP_LOGD(TAG, "Received invalid BSSID"); - } else if (req->cmd_set_config->ssid.len >= sizeof(req_data.ssid)) { - ESP_LOGD(TAG, "Received invalid SSID"); - } else if (req->cmd_set_config->passphrase.len >= sizeof(req_data.password)) { - ESP_LOGD(TAG, "Received invalid Passphrase"); - } else { - /* The received SSID and Passphrase are not NULL terminated so - * we memcpy over zeroed out arrays. Above length checks ensure - * that there is atleast 1 extra byte for null termination */ - memcpy(req_data.ssid, req->cmd_set_config->ssid.data, - req->cmd_set_config->ssid.len); - memcpy(req_data.password, req->cmd_set_config->passphrase.data, - req->cmd_set_config->passphrase.len); - memcpy(req_data.bssid, req->cmd_set_config->bssid.data, - req->cmd_set_config->bssid.len); - req_data.channel = req->cmd_set_config->channel; - if (h->set_config_handler(&req_data, &h->ctx) == ESP_OK) { - resp_payload->status = STATUS__Success; - } else { - resp_payload->status = STATUS__InternalError; - } - } - - resp->payload_case = WI_FI_CONFIG_PAYLOAD__PAYLOAD_RESP_SET_CONFIG; - resp->resp_set_config = resp_payload; - return ESP_OK; -} - -static esp_err_t cmd_apply_config_handler(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data) -{ - ESP_LOGD(TAG, "Enter cmd_apply_config_handler"); - wifi_prov_config_handlers_t *h = (wifi_prov_config_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespApplyConfig *resp_payload = (RespApplyConfig *) malloc(sizeof(RespApplyConfig)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - - resp_apply_config__init(resp_payload); - - if (h->apply_config_handler(&h->ctx) == ESP_OK) { - resp_payload->status = STATUS__Success; - } else { - resp_payload->status = STATUS__InternalError; - } - - resp->payload_case = WI_FI_CONFIG_PAYLOAD__PAYLOAD_RESP_APPLY_CONFIG; - resp->resp_apply_config = resp_payload; - return ESP_OK; -} - -static int lookup_cmd_handler(int cmd_id) -{ - for (size_t i = 0; i < sizeof(cmd_table)/sizeof(wifi_prov_config_cmd_t); i++) { - if (cmd_table[i].cmd_num == cmd_id) { - return i; - } - } - - return -1; -} -static void wifi_prov_config_command_cleanup(WiFiConfigPayload *resp, void *priv_data) -{ - if (!resp) { - return; - } - - switch (resp->msg) { - case WI_FI_CONFIG_MSG_TYPE__TypeRespGetStatus: - { - switch (resp->resp_get_status->sta_state) { - case WIFI_STATION_STATE__Connecting: - break; - case WIFI_STATION_STATE__Connected: - if (resp->resp_get_status->connected) { - if (resp->resp_get_status->connected->ip4_addr) { - free(resp->resp_get_status->connected->ip4_addr); - } - if (resp->resp_get_status->connected->bssid.data) { - free(resp->resp_get_status->connected->bssid.data); - } - if (resp->resp_get_status->connected->ssid.data) { - free(resp->resp_get_status->connected->ssid.data); - } - free(resp->resp_get_status->connected); - } - break; - case WIFI_STATION_STATE__ConnectionFailed: - break; - default: - break; - } - free(resp->resp_get_status); - } - break; - case WI_FI_CONFIG_MSG_TYPE__TypeRespSetConfig: - { - free(resp->resp_set_config); - } - break; - case WI_FI_CONFIG_MSG_TYPE__TypeRespApplyConfig: - { - free(resp->resp_apply_config); - } - break; - default: - ESP_LOGE(TAG, "Unsupported response type in cleanup_handler"); - break; - } - return; -} - -static esp_err_t wifi_prov_config_command_dispatcher(WiFiConfigPayload *req, - WiFiConfigPayload *resp, void *priv_data) -{ - esp_err_t ret; - - ESP_LOGD(TAG, "In wifi_prov_config_command_dispatcher Cmd=%d", req->msg); - - int cmd_index = lookup_cmd_handler(req->msg); - if (cmd_index < 0) { - ESP_LOGE(TAG, "Invalid command handler lookup"); - return ESP_FAIL; - } - - ret = cmd_table[cmd_index].command_handler(req, resp, priv_data); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Error executing command handler"); - return ESP_FAIL; - } - - return ESP_OK; -} - -esp_err_t wifi_prov_config_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, - uint8_t **outbuf, ssize_t *outlen, void *priv_data) -{ - WiFiConfigPayload *req; - WiFiConfigPayload resp; - esp_err_t ret; - - req = wi_fi_config_payload__unpack(NULL, inlen, inbuf); - if (!req) { - ESP_LOGE(TAG, "Unable to unpack config data"); - return ESP_ERR_INVALID_ARG; - } - - wi_fi_config_payload__init(&resp); - ret = wifi_prov_config_command_dispatcher(req, &resp, priv_data); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Proto command dispatcher error %d", ret); - return ESP_FAIL; - } - - resp.msg = req->msg + 1; /* Response is request + 1 */ - wi_fi_config_payload__free_unpacked(req, NULL); - - *outlen = wi_fi_config_payload__get_packed_size(&resp); - if (*outlen <= 0) { - ESP_LOGE(TAG, "Invalid encoding for response"); - return ESP_FAIL; - } - - *outbuf = (uint8_t *) malloc(*outlen); - if (!*outbuf) { - ESP_LOGE(TAG, "System out of memory"); - return ESP_ERR_NO_MEM; - } - wi_fi_config_payload__pack(&resp, *outbuf); - wifi_prov_config_command_cleanup(&resp, priv_data); - - return ESP_OK; -} diff --git a/components/wifi_provisioning/src/wifi_ctrl.c b/components/wifi_provisioning/src/wifi_ctrl.c deleted file mode 100644 index 2cf496b27bda..000000000000 --- a/components/wifi_provisioning/src/wifi_ctrl.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include "wifi_ctrl.pb-c.h" - -#include "wifi_ctrl.h" - -static const char *TAG = "proto_wifi_ctrl"; - -typedef struct wifi_ctrl_cmd { - int cmd_id; - esp_err_t (*command_handler)(WiFiCtrlPayload *req, - WiFiCtrlPayload *resp, void *priv_data); -} wifi_ctrl_cmd_t; - -static esp_err_t cmd_ctrl_reset_handler(WiFiCtrlPayload *req, - WiFiCtrlPayload *resp, - void *priv_data); - -static esp_err_t cmd_ctrl_reprov_handler(WiFiCtrlPayload *req, - WiFiCtrlPayload *resp, - void *priv_data); - -static wifi_ctrl_cmd_t cmd_table[] = { - { - .cmd_id = WI_FI_CTRL_MSG_TYPE__TypeCmdCtrlReset, - .command_handler = cmd_ctrl_reset_handler - }, - { - .cmd_id = WI_FI_CTRL_MSG_TYPE__TypeCmdCtrlReprov, - .command_handler = cmd_ctrl_reprov_handler - }, -}; - -static esp_err_t cmd_ctrl_reset_handler(WiFiCtrlPayload *req, - WiFiCtrlPayload *resp, void *priv_data) -{ - wifi_ctrl_handlers_t *h = (wifi_ctrl_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespCtrlReset *resp_payload = (RespCtrlReset *) malloc(sizeof(RespCtrlReset)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - - resp_ctrl_reset__init(resp_payload); - resp->status = (h->ctrl_reset() == ESP_OK ? - STATUS__Success : STATUS__InternalError); - resp->payload_case = WI_FI_CTRL_PAYLOAD__PAYLOAD_RESP_CTRL_RESET; - resp->resp_ctrl_reset = resp_payload; - return ESP_OK; -} - -static esp_err_t cmd_ctrl_reprov_handler(WiFiCtrlPayload *req, - WiFiCtrlPayload *resp, void *priv_data) -{ - wifi_ctrl_handlers_t *h = (wifi_ctrl_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespCtrlReprov *resp_payload = (RespCtrlReprov *) malloc(sizeof(RespCtrlReprov)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - - resp_ctrl_reprov__init(resp_payload); - resp->status = (h->ctrl_reprov() == ESP_OK ? - STATUS__Success : STATUS__InternalError); - resp->payload_case = WI_FI_CTRL_PAYLOAD__PAYLOAD_RESP_CTRL_REPROV; - resp->resp_ctrl_reprov = resp_payload; - return ESP_OK; -} - -static int lookup_cmd_handler(int cmd_id) -{ - for (size_t i = 0; i < sizeof(cmd_table)/sizeof(wifi_ctrl_cmd_t); i++) { - if (cmd_table[i].cmd_id == cmd_id) { - return i; - } - } - - return -1; -} - -static void wifi_ctrl_cmd_cleanup(WiFiCtrlPayload *resp, void *priv_data) -{ - switch (resp->msg) { - case WI_FI_CTRL_MSG_TYPE__TypeRespCtrlReset: - { - free(resp->resp_ctrl_reset); - } - break; - case WI_FI_CTRL_MSG_TYPE__TypeRespCtrlReprov: - { - free(resp->resp_ctrl_reprov); - } - break; - default: - ESP_LOGE(TAG, "Unsupported response type in cleanup_handler"); - break; - } - return; -} - -static esp_err_t wifi_ctrl_cmd_dispatcher(WiFiCtrlPayload *req, - WiFiCtrlPayload *resp, void *priv_data) -{ - esp_err_t ret; - - ESP_LOGD(TAG, "In wifi_ctrl_cmd_dispatcher Cmd=%d", req->msg); - - int cmd_index = lookup_cmd_handler(req->msg); - if (cmd_index < 0) { - ESP_LOGE(TAG, "Failed to find cmd with ID = %d in the command table", req->msg); - return ESP_FAIL; - } - - ret = cmd_table[cmd_index].command_handler(req, resp, priv_data); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Error executing command handler"); - } - - return ret; -} - -esp_err_t wifi_ctrl_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, - uint8_t **outbuf, ssize_t *outlen, void *priv_data) -{ - WiFiCtrlPayload *req; - WiFiCtrlPayload resp; - esp_err_t ret = ESP_OK; - - req = wi_fi_ctrl_payload__unpack(NULL, inlen, inbuf); - if (!req) { - ESP_LOGE(TAG, "Unable to unpack ctrl message"); - return ESP_ERR_INVALID_ARG; - } - - wi_fi_ctrl_payload__init(&resp); - ret = wifi_ctrl_cmd_dispatcher(req, &resp, priv_data); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Command dispatcher error %02X", ret); - ret = ESP_FAIL; - goto exit; - } - - resp.msg = req->msg + 1; /* Response is request + 1 */ - *outlen = wi_fi_ctrl_payload__get_packed_size(&resp); - if (*outlen <= 0) { - ESP_LOGE(TAG, "Invalid encoding for response"); - ret = ESP_FAIL; - goto exit; - } - - *outbuf = (uint8_t *) malloc(*outlen); - if (!*outbuf) { - ESP_LOGE(TAG, "Failed to allocate memory for the output buffer"); - ret = ESP_ERR_NO_MEM; - goto exit; - } - wi_fi_ctrl_payload__pack(&resp, *outbuf); - ESP_LOGD(TAG, "Response packet size : %d", *outlen); - exit: - - wi_fi_ctrl_payload__free_unpacked(req, NULL); - wifi_ctrl_cmd_cleanup(&resp, priv_data); - return ret; -} diff --git a/components/wifi_provisioning/src/wifi_ctrl.h b/components/wifi_provisioning/src/wifi_ctrl.h deleted file mode 100644 index dd6fc5062423..000000000000 --- a/components/wifi_provisioning/src/wifi_ctrl.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _PROV_WIFI_CTRL_H_ -#define _PROV_WIFI_CTRL_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Internal handlers for receiving and responding to protocomm - * requests from client - * - * This is to be passed as priv_data for protocomm request handler - * (refer to `wifi_ctrl_handler()`) when calling `protocomm_add_endpoint()`. - */ -typedef struct wifi_ctrl_handlers { - /** - * Handler function called when ctrl reset command is received - */ - esp_err_t (*ctrl_reset)(void); - - /** - * Handler function called when ctrl reprov command is received - */ - esp_err_t (*ctrl_reprov)(void); - -} wifi_ctrl_handlers_t; - -/** - * @brief Handler for sending on demand Wi-Fi ctrl results - * - * This is to be registered as the `prov-ctrl` endpoint handler - * (protocomm `protocomm_req_handler_t`) using `protocomm_add_endpoint()` - */ -esp_err_t wifi_ctrl_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, - uint8_t **outbuf, ssize_t *outlen, void *priv_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/wifi_provisioning/src/wifi_provisioning_priv.h b/components/wifi_provisioning/src/wifi_provisioning_priv.h deleted file mode 100644 index a58d2589d922..000000000000 --- a/components/wifi_provisioning/src/wifi_provisioning_priv.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include - -#include "wifi_provisioning/manager.h" -#include "wifi_provisioning/wifi_config.h" -#include "wifi_provisioning/wifi_scan.h" -#include "wifi_ctrl.h" - -/** - * @brief Notify manager that provisioning is done - * - * Stops the provisioning. This is called by the get_status_handler() - * when the status is connected. This has no effect if main application - * has disabled auto stop on completion by calling - * wifi_prov_mgr_disable_auto_stop() - * - * @return - * - ESP_OK : Provisioning will be stopped - * - ESP_FAIL : Failed to stop provisioning - */ -esp_err_t wifi_prov_mgr_done(void); - -/** - * @brief Start Wi-Fi AP Scan - * - * @param[in] blocking Set true to return only after scanning is complete - * @param[in] passive Set true to perform passive scan instead of default active scan - * @param[in] group_channels Number of channels to scan in one go - * (set to 0 for scanning all channels in one go) - * @param[in] period_ms Scan time (in milli-seconds) on each channel - * - * @return - * - ESP_OK : Successfully started Wi-Fi scanning - * - ESP_FAIL : Provisioning app not running - */ -esp_err_t wifi_prov_mgr_wifi_scan_start(bool blocking, bool passive, - uint8_t group_channels, - uint32_t period_ms); - -/** - * @brief Use to query the state of Wi-Fi scan - * - * @return - * - true : Scan finished - * - false : Scan running - */ -bool wifi_prov_mgr_wifi_scan_finished(void); - -/** - * @brief Get the count of results in the scan list - * - * @return - * - count : Number of Wi-Fi Access Points detected while scanning - */ -uint16_t wifi_prov_mgr_wifi_scan_result_count(void); - -/** - * @brief Get AP record for a particular index in the scan list result - * - * @param[out] index Index of the result to fetch - * - * @return - * - result : Pointer to Access Point record - */ -const wifi_ap_record_t *wifi_prov_mgr_wifi_scan_result(uint16_t index); - -/** - * @brief Get protocomm handlers for wifi_config provisioning endpoint - * - * @param[out] ptr pointer to structure to be set - * - * @return - * - ESP_OK : success - * - ESP_ERR_INVALID_ARG : null argument - */ -esp_err_t get_wifi_prov_handlers(wifi_prov_config_handlers_t *ptr); - -/** - * @brief Get protocomm handlers for wifi_scan provisioning endpoint - * - * @param[out] ptr pointer to structure to be set - * - * @return - * - ESP_OK : success - * - ESP_ERR_INVALID_ARG : null argument - */ -esp_err_t get_wifi_scan_handlers(wifi_prov_scan_handlers_t *ptr); - -/** - * @brief Get protocomm handlers for wifi_ctrl provisioning endpoint - * - * @param[in] ptr pointer to structure to be set - * - * @return - * - ESP_OK : success - * - ESP_ERR_INVALID_ARG : null argument - */ -esp_err_t get_wifi_ctrl_handlers(wifi_ctrl_handlers_t *ptr); diff --git a/components/wifi_provisioning/src/wifi_scan.c b/components/wifi_provisioning/src/wifi_scan.c deleted file mode 100644 index bfc0596f5215..000000000000 --- a/components/wifi_provisioning/src/wifi_scan.c +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include - -#include "wifi_scan.pb-c.h" - -#include - -static const char *TAG = "proto_wifi_scan"; - -typedef struct wifi_prov_scan_cmd { - int cmd_num; - esp_err_t (*command_handler)(WiFiScanPayload *req, - WiFiScanPayload *resp, void *priv_data); -} wifi_prov_scan_cmd_t; - -static esp_err_t cmd_scan_start_handler(WiFiScanPayload *req, - WiFiScanPayload *resp, - void *priv_data); - -static esp_err_t cmd_scan_status_handler(WiFiScanPayload *req, - WiFiScanPayload *resp, - void *priv_data); - -static esp_err_t cmd_scan_result_handler(WiFiScanPayload *req, - WiFiScanPayload *resp, - void *priv_data); - -static wifi_prov_scan_cmd_t cmd_table[] = { - { - .cmd_num = WI_FI_SCAN_MSG_TYPE__TypeCmdScanStart, - .command_handler = cmd_scan_start_handler - }, - { - .cmd_num = WI_FI_SCAN_MSG_TYPE__TypeCmdScanStatus, - .command_handler = cmd_scan_status_handler - }, - { - .cmd_num = WI_FI_SCAN_MSG_TYPE__TypeCmdScanResult, - .command_handler = cmd_scan_result_handler - } -}; - -static esp_err_t cmd_scan_start_handler(WiFiScanPayload *req, - WiFiScanPayload *resp, void *priv_data) -{ - wifi_prov_scan_handlers_t *h = (wifi_prov_scan_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespScanStart *resp_payload = (RespScanStart *) malloc(sizeof(RespScanStart)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - - resp_scan_start__init(resp_payload); - resp->status = (h->scan_start(req->cmd_scan_start->blocking, - req->cmd_scan_start->passive, - req->cmd_scan_start->group_channels, - req->cmd_scan_start->period_ms, - &h->ctx) == ESP_OK ? - STATUS__Success : STATUS__InternalError); - resp->payload_case = WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_START; - resp->resp_scan_start = resp_payload; - return ESP_OK; -} - -static esp_err_t cmd_scan_status_handler(WiFiScanPayload *req, - WiFiScanPayload *resp, void *priv_data) -{ - bool scan_finished = false; - uint16_t result_count = 0; - - wifi_prov_scan_handlers_t *h = (wifi_prov_scan_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespScanStatus *resp_payload = (RespScanStatus *) malloc(sizeof(RespScanStatus)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - - resp_scan_status__init(resp_payload); - resp->status = (h->scan_status(&scan_finished, &result_count, &h->ctx) == ESP_OK ? - STATUS__Success : STATUS__InternalError); - resp_payload->scan_finished = scan_finished; - resp_payload->result_count = result_count; - resp->payload_case = WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_STATUS; - resp->resp_scan_status = resp_payload; - return ESP_OK; -} - -static esp_err_t cmd_scan_result_handler(WiFiScanPayload *req, - WiFiScanPayload *resp, void *priv_data) -{ - esp_err_t err; - wifi_prov_scan_result_t scan_result = {{0}, {0}, 0, 0, 0}; - WiFiScanResult **results = NULL; - wifi_prov_scan_handlers_t *h = (wifi_prov_scan_handlers_t *) priv_data; - if (!h) { - ESP_LOGE(TAG, "Command invoked without handlers"); - return ESP_ERR_INVALID_STATE; - } - - RespScanResult *resp_payload = (RespScanResult *) malloc(sizeof(RespScanResult)); - if (!resp_payload) { - ESP_LOGE(TAG, "Error allocating memory"); - return ESP_ERR_NO_MEM; - } - resp_scan_result__init(resp_payload); - - resp->status = STATUS__Success; - resp->payload_case = WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_RESULT; - resp->resp_scan_result = resp_payload; - /* Allocate memory only if there are non-zero scan results */ - if (req->cmd_scan_result->count) { - results = (WiFiScanResult **) calloc(req->cmd_scan_result->count, - sizeof(WiFiScanResult *)); - if (!results) { - ESP_LOGE(TAG, "Failed to allocate memory for results array"); - return ESP_ERR_NO_MEM; - } - } - resp_payload->entries = results; - resp_payload->n_entries = req->cmd_scan_result->count; - - /* If req->cmd_scan_result->count is 0, the below loop will - * be skipped. - */ - for (uint16_t i = 0; i < req->cmd_scan_result->count; i++) { - err = h->scan_result(i + req->cmd_scan_result->start_index, - &scan_result, &h->ctx); - if (err != ESP_OK) { - resp->status = STATUS__InternalError; - break; - } - - results[i] = (WiFiScanResult *) malloc(sizeof(WiFiScanResult)); - if (!results[i]) { - ESP_LOGE(TAG, "Failed to allocate memory for result entry"); - return ESP_ERR_NO_MEM; - } - wi_fi_scan_result__init(results[i]); - - results[i]->ssid.len = strnlen(scan_result.ssid, 32); - results[i]->ssid.data = (uint8_t *) strndup(scan_result.ssid, 32); - if (!results[i]->ssid.data) { - ESP_LOGE(TAG, "Failed to allocate memory for scan result entry SSID"); - return ESP_ERR_NO_MEM; - } - - results[i]->channel = scan_result.channel; - results[i]->rssi = scan_result.rssi; - results[i]->auth = scan_result.auth; - - results[i]->bssid.len = sizeof(scan_result.bssid); - results[i]->bssid.data = malloc(results[i]->bssid.len); - if (!results[i]->bssid.data) { - ESP_LOGE(TAG, "Failed to allocate memory for scan result entry BSSID"); - return ESP_ERR_NO_MEM; - } - memcpy(results[i]->bssid.data, scan_result.bssid, results[i]->bssid.len); - } - return ESP_OK; -} - - -static int lookup_cmd_handler(int cmd_id) -{ - for (size_t i = 0; i < sizeof(cmd_table)/sizeof(wifi_prov_scan_cmd_t); i++) { - if (cmd_table[i].cmd_num == cmd_id) { - return i; - } - } - - return -1; -} - -static void wifi_prov_scan_cmd_cleanup(WiFiScanPayload *resp, void *priv_data) -{ - switch (resp->msg) { - case WI_FI_SCAN_MSG_TYPE__TypeRespScanStart: - { - free(resp->resp_scan_start); - } - break; - case WI_FI_SCAN_MSG_TYPE__TypeRespScanStatus: - { - free(resp->resp_scan_status); - } - break; - case WI_FI_SCAN_MSG_TYPE__TypeRespScanResult: - { - if (!resp->resp_scan_result) return; - if (resp->resp_scan_result->entries) { - for (uint16_t i = 0; i < resp->resp_scan_result->n_entries; i++) { - if (!resp->resp_scan_result->entries[i]) continue; - free(resp->resp_scan_result->entries[i]->ssid.data); - free(resp->resp_scan_result->entries[i]->bssid.data); - free(resp->resp_scan_result->entries[i]); - } - free(resp->resp_scan_result->entries); - } - free(resp->resp_scan_result); - } - break; - default: - ESP_LOGE(TAG, "Unsupported response type in cleanup_handler"); - break; - } - return; -} - -static esp_err_t wifi_prov_scan_cmd_dispatcher(WiFiScanPayload *req, - WiFiScanPayload *resp, void *priv_data) -{ - esp_err_t ret; - - ESP_LOGD(TAG, "In wifi_prov_scan_cmd_dispatcher Cmd=%d", req->msg); - - int cmd_index = lookup_cmd_handler(req->msg); - if (cmd_index < 0) { - ESP_LOGE(TAG, "Invalid command handler lookup"); - return ESP_FAIL; - } - - ret = cmd_table[cmd_index].command_handler(req, resp, priv_data); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Error executing command handler"); - return ESP_FAIL; - } - - return ESP_OK; -} - -esp_err_t wifi_prov_scan_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, - uint8_t **outbuf, ssize_t *outlen, void *priv_data) -{ - WiFiScanPayload *req; - WiFiScanPayload resp; - esp_err_t ret = ESP_OK; - - req = wi_fi_scan_payload__unpack(NULL, inlen, inbuf); - if (!req) { - ESP_LOGE(TAG, "Unable to unpack scan message"); - return ESP_ERR_INVALID_ARG; - } - - wi_fi_scan_payload__init(&resp); - ret = wifi_prov_scan_cmd_dispatcher(req, &resp, priv_data); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Command dispatcher error %d", ret); - ret = ESP_FAIL; - goto exit; - } - - resp.msg = req->msg + 1; /* Response is request + 1 */ - *outlen = wi_fi_scan_payload__get_packed_size(&resp); - if (*outlen <= 0) { - ESP_LOGE(TAG, "Invalid encoding for response"); - ret = ESP_FAIL; - goto exit; - } - - *outbuf = (uint8_t *) malloc(*outlen); - if (!*outbuf) { - ESP_LOGE(TAG, "System out of memory"); - ret = ESP_ERR_NO_MEM; - goto exit; - } - wi_fi_scan_payload__pack(&resp, *outbuf); - ESP_LOGD(TAG, "Response packet size : %d", *outlen); - exit: - - wi_fi_scan_payload__free_unpacked(req, NULL); - wifi_prov_scan_cmd_cleanup(&resp, priv_data); - return ret; -} diff --git a/install.sh b/install.sh index 868665c527d5..46badce82a64 100755 --- a/install.sh +++ b/install.sh @@ -26,12 +26,12 @@ done TARGETS=$("${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract targets "$@") echo "Installing ESP-IDF tools" -"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install --targets="${TARGETS}" +"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" --non-interactive install --targets="${TARGETS}" FEATURES=$("${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract features "$@") echo "Installing Python environment and packages" -"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install-python-env --features="${FEATURES}" +"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" --non-interactive install-python-env --features="${FEATURES}" echo "All done! You can now run:" echo "" diff --git a/package.json b/package.json new file mode 100644 index 000000000000..82692d0b8105 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "framework-espidf", + "version": "3.50300", + "description": "Espressif IoT Development Framework. Tasmota development framework for ESP32 chip", + "keywords": [ + "framework", + "esp32", + "esp32s2", + "esp32s3", + "esp32c2", + "esp32c3", + "esp32c5", + "esp32c6", + "esp32h2", + "esp32p4", + "espressif" + ], + "homepage": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32/", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/tasmota/esp-idf" + } +} diff --git a/version.txt b/version.txt new file mode 100644 index 000000000000..1adfb54b5a66 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +5.3.0.240819