Merge branch 'master' into feature/cmake_update

This commit is contained in:
Angus Gratton
2018-05-30 17:41:35 +10:00
committed by Angus Gratton
1102 changed files with 77153 additions and 96172 deletions

View File

@@ -25,13 +25,13 @@ else()
# tcpip_adapter is a public requirement because esp_event.h uses tcpip_adapter types
set(COMPONENT_PRIV_REQUIRES
app_trace bootloader_support ethernet log mbedtls nvs_flash
pthread spi_flash vfs wpa_supplicant xtensa-debug-module)
pthread smartconfig_ack spi_flash vfs wpa_supplicant xtensa-debug-module)
register_component()
target_link_libraries(esp32 "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib")
if(NOT CONFIG_NO_BLOBS)
target_link_libraries(esp32 coexist core espnow net80211 phy pp rtc smartconfig wpa2 wpa wps)
target_link_libraries(esp32 coexist core espnow mesh net80211 phy pp rtc smartconfig wpa2 wpa wps)
endif()
target_linker_script(esp32 "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")

View File

@@ -512,6 +512,13 @@ config ESP32_DEBUG_OCDAWARE
The FreeRTOS panic and unhandled exception handers can detect a JTAG OCD debugger and
instead of panicking, have the debugger stop on the offending instruction.
config ESP32_DEBUG_STUBS_ENABLE
bool "OpenOCD debug stubs"
default OPTIMIZATION_LEVEL_DEBUG
depends on !ESP32_TRAX
help
Debug stubs are used by OpenOCD to execute pre-compiled onboard code which does some useful debugging,
e.g. GCOV data dump.
config INT_WDT
bool "Interrupt watchdog"
@@ -685,7 +692,8 @@ endchoice
config ESP32_RTC_CLK_CAL_CYCLES
int "Number of cycles for RTC_SLOW_CLK calibration"
default 1024
default 3000 if ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL
default 1024 if ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC
range 0 125000
help
When the startup code initializes RTC_SLOW_CLK, it can perform
@@ -698,18 +706,27 @@ config ESP32_RTC_CLK_CAL_CYCLES
When this option is set to 0, clock calibration will not be performed at
startup, and approximate clock frequencies will be assumed:
- 150000 Hz if internal RC oscillator is used as clock source
- 32768 Hz if the 32k crystal oscillator is used
- 150000 Hz if internal RC oscillator is used as clock source. For this use value 1024.
- 32768 Hz if the 32k crystal oscillator is used. For this use value 3000 or more.
In case more value will help improve the definition of the launch of the crystal.
If the crystal could not start, it will be switched to internal RC.
config ESP32_RTC_XTAL_BOOTSTRAP_CYCLES
int "Bootstrap cycles for external 32kHz crystal"
default 100
depends on ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL
default 5
range 0 32768
help
To reduce the startup time of an external RTC crystal,
we bootstrap it with a 32kHz square wave for a fixed number of cycles.
Setting 0 will disable bootstrapping (if disabled, the crystal may take
longer to start up or fail to oscillate under some conditions).
If this value is too high, a faulty crystal may initially start and then fail.
If this value is too low, an otherwise good crystal may not start.
To accurately determine if the crystal has started,
set a larger "Number of cycles for RTC_SLOW_CLK calibration" (about 3000).
config ESP32_DEEP_SLEEP_WAKEUP_DELAY
int "Extra delay in deep sleep wake stub (in us)"
@@ -835,9 +852,9 @@ choice SW_COEXIST_PREFERENCE
default SW_COEXIST_PREFERENCE_BALANCE
help
Choose Bluetooth/WiFi/Balance for different preference.
If choose WiFi, it will make WiFi performance better. Such, keep WiFi Audio more smooth.
If choose Bluetooth, it will make Bluetooth performance better. Such, keep Bluetooth(A2DP) Audio more smooth.
If choose Balance, the performance of WiFi and bluetooth will be balance. It's default.
If choose WiFi, it will make WiFi performance better. Such, keep WiFi Audio more fluent.
If choose Bluetooth, it will make Bluetooth performance better. Such, keep Bluetooth(A2DP) Audio more fluent.
If choose Balance, the performance of WiFi and bluetooth will be balance. It's default. Normally, just choose balance, the A2DP audio can play fluently, too.
Except config preference in menuconfig, you can also call esp_coex_preference_set() dynamically.
config SW_COEXIST_PREFERENCE_WIFI
@@ -946,35 +963,37 @@ config ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
can deliver frames faster than WiFi layer can transmit. In these cases, we may run out of TX
buffers.
config ESP32_WIFI_CSI_ENABLED
bool "WiFi CSI(Channel State Information)"
default n
help
Select this option to enable CSI(Channel State Information) feature. CSI takes about
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM KB of RAM. If CSI is not used, it is better to disable
this feature in order to save memory.
config ESP32_WIFI_AMPDU_TX_ENABLED
bool "WiFi AMPDU TX"
default y if SW_COEXIST_ENABLE
default y
help
Select this option to enable AMPDU TX feature
Suggest enable it when SW_COEXIST_ENABLE is defined.
config ESP32_WIFI_TX_BA_WIN
int "WiFi AMPDU TX BA window size"
depends on ESP32_WIFI_AMPDU_TX_ENABLED
range 2 32
default 2 if SW_COEXIST_ENABLE
default 6
help
Set the size of WiFi Block Ack TX window. Generally a bigger value means higher throughput but
more memory. Most of time we should NOT change the default value unless special reason, e.g.
test the maximum UDP TX throughput with iperf etc. For iperf test in shieldbox, the recommended
value is 9~12. If SW_COEXIST_ENABLE is defined, suggest value is 2.
value is 9~12.
config ESP32_WIFI_AMPDU_RX_ENABLED
bool "WiFi AMPDU RX"
depends on !SW_COEXIST_ENABLE
default y
default y
help
Select this option to enable AMPDU RX feature
Suggest disable this option when SW_COEXIST_ENABLE is enabled. It can improve WiFi RX performance normally.
config ESP32_WIFI_RX_BA_WIN
int "WiFi AMPDU RX BA window size"
@@ -993,6 +1012,19 @@ config ESP32_WIFI_NVS_ENABLED
help
Select this option to enable WiFi NVS flash
choice ESP32_WIFI_TASK_CORE_ID
depends on !FREERTOS_UNICORE
prompt "WiFi Task Core ID"
default ESP32_WIFI_TASK_PINNED_TO_CORE_0
help
Pinned WiFi task to core 0 or core 1.
config ESP32_WIFI_TASK_PINNED_TO_CORE_0
bool "Core 0"
config ESP32_WIFI_TASK_PINNED_TO_CORE_1
bool "Core 1"
endchoice
endmenu # Wi-Fi
menu PHY

View File

@@ -36,7 +36,6 @@
* Larger values increase startup delay. Smaller values may cause false positive
* detection (i.e. oscillator runs for a few cycles and then stops).
*/
#define XTAL_32K_DETECT_CYCLES 32
#define SLOW_CLK_CAL_CYCLES CONFIG_ESP32_RTC_CLK_CAL_CYCLES
#define MHZ (1000000)
@@ -128,6 +127,9 @@ void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
static void select_rtc_slow_clk(rtc_slow_freq_t slow_clk)
{
uint32_t cal_val = 0;
uint32_t wait = 0;
const uint32_t warning_timeout = 3 /* sec */ * 32768 /* Hz */ / (2 * SLOW_CLK_CAL_CYCLES);
bool changing_clock_to_150k = false;
do {
if (slow_clk == RTC_SLOW_FREQ_32K_XTAL) {
/* 32k XTAL oscillator needs to be enabled and running before it can
@@ -137,24 +139,23 @@ static void select_rtc_slow_clk(rtc_slow_freq_t slow_clk)
* oscillator cycles. If the 32k XTAL has not started up, calibration
* will time out, returning 0.
*/
uint32_t wait = 0;
// increment of 'wait' counter equivalent to 3 seconds
const uint32_t warning_timeout = 3 /* sec */ * 32768 /* Hz */ / (2 * XTAL_32K_DETECT_CYCLES);
ESP_EARLY_LOGD(TAG, "waiting for 32k oscillator to start up");
do {
++wait;
rtc_clk_32k_enable(true);
cal_val = rtc_clk_cal(RTC_CAL_32K_XTAL, XTAL_32K_DETECT_CYCLES);
if (wait % warning_timeout == 0) {
ESP_EARLY_LOGW(TAG, "still waiting for 32k oscillator to start up");
}
if(cal_val == 0){
rtc_clk_32k_enable(false);
rtc_clk_32k_bootstrap(CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES);
}
} while (cal_val == 0);
rtc_clk_32k_enable(true);
cal_val = rtc_clk_cal(RTC_CAL_32K_XTAL, SLOW_CLK_CAL_CYCLES);
if(cal_val == 0 || cal_val < 15000000L){
ESP_EARLY_LOGE(TAG, "RTC: Not found External 32 kHz XTAL. Switching to Internal 150 kHz RC chain");
slow_clk = RTC_SLOW_FREQ_RTC;
changing_clock_to_150k = true;
}
}
rtc_clk_slow_freq_set(slow_clk);
if (changing_clock_to_150k == true && wait > 1){
// This helps when there are errors when switching the clock from External 32 kHz XTAL to Internal 150 kHz RC chain.
rtc_clk_32k_enable(false);
uint32_t min_bootstrap = 5; // Min bootstrapping for continue switching the clock.
rtc_clk_32k_bootstrap(min_bootstrap);
rtc_clk_32k_enable(true);
}
if (SLOW_CLK_CAL_CYCLES > 0) {
/* TODO: 32k XTAL oscillator has some frequency drift at startup.
@@ -165,6 +166,9 @@ static void select_rtc_slow_clk(rtc_slow_freq_t slow_clk)
const uint64_t cal_dividend = (1ULL << RTC_CLK_CAL_FRACT) * 1000000ULL;
cal_val = (uint32_t) (cal_dividend / rtc_clk_slow_freq_get_hz());
}
if (++wait % warning_timeout == 0) {
ESP_EARLY_LOGW(TAG, "still waiting for source selection RTC");
}
} while (cal_val == 0);
ESP_EARLY_LOGD(TAG, "RTC_SLOW_CLK calibration value: %d", cal_val);
esp_clk_slowclk_cal_set(cal_val);
@@ -211,31 +215,12 @@ void esp_perip_clk_init(void)
}
else {
common_perip_clk = DPORT_WDG_CLK_EN |
DPORT_I2S0_CLK_EN |
#if CONFIG_CONSOLE_UART_NUM != 0
DPORT_UART_CLK_EN |
#endif
#if CONFIG_CONSOLE_UART_NUM != 1
DPORT_UART1_CLK_EN |
#endif
#if CONFIG_CONSOLE_UART_NUM != 2
DPORT_UART2_CLK_EN |
#endif
DPORT_SPI_CLK_EN |
DPORT_I2C_EXT0_CLK_EN |
DPORT_UHCI0_CLK_EN |
DPORT_RMT_CLK_EN |
DPORT_PCNT_CLK_EN |
DPORT_LEDC_CLK_EN |
DPORT_UHCI1_CLK_EN |
DPORT_TIMERGROUP1_CLK_EN |
DPORT_SPI_CLK_EN_2 |
DPORT_PWM0_CLK_EN |
DPORT_I2C_EXT1_CLK_EN |
DPORT_CAN_CLK_EN |
DPORT_PWM1_CLK_EN |
DPORT_I2S1_CLK_EN |
DPORT_SPI_DMA_CLK_EN |
DPORT_PWM2_CLK_EN |
DPORT_PWM3_CLK_EN;
hwcrypto_perip_clk = DPORT_PERI_EN_AES |
@@ -251,13 +236,33 @@ void esp_perip_clk_init(void)
DPORT_WIFI_CLK_EMAC_EN;
}
//Reset the communication peripherals like I2C, SPI, UART, I2S and bring them to known state.
common_perip_clk |= DPORT_I2S0_CLK_EN |
#if CONFIG_CONSOLE_UART_NUM != 0
DPORT_UART_CLK_EN |
#endif
#if CONFIG_CONSOLE_UART_NUM != 1
DPORT_UART1_CLK_EN |
#endif
#if CONFIG_CONSOLE_UART_NUM != 2
DPORT_UART2_CLK_EN |
#endif
DPORT_SPI2_CLK_EN |
DPORT_I2C_EXT0_CLK_EN |
DPORT_UHCI0_CLK_EN |
DPORT_RMT_CLK_EN |
DPORT_UHCI1_CLK_EN |
DPORT_SPI3_CLK_EN |
DPORT_I2C_EXT1_CLK_EN |
DPORT_I2S1_CLK_EN |
DPORT_SPI_DMA_CLK_EN;
#if CONFIG_SPIRAM_SPEED_80M
//80MHz SPIRAM uses SPI2 as well; it's initialized before this is called. Because it is used in
//80MHz SPIRAM uses SPI3 as well; it's initialized before this is called. Because it is used in
//a weird mode where clock to the peripheral is disabled but reset is also disabled, it 'hangs'
//in a state where it outputs a continuous 80MHz signal. Mask its bit here because we should
//not modify that state, regardless of what we calculated earlier.
common_perip_clk &= ~DPORT_SPI_CLK_EN_2;
common_perip_clk &= ~DPORT_SPI3_CLK_EN;
#endif
/* Change I2S clock to audio PLL first. Because if I2S uses 160MHz clock,

View File

@@ -61,6 +61,7 @@
#include "esp_panic.h"
#include "esp_core_dump.h"
#include "esp_app_trace.h"
#include "esp_dbg_stubs.h"
#include "esp_efuse.h"
#include "esp_spiram.h"
#include "esp_clk_internal.h"
@@ -332,6 +333,9 @@ void start_cpu0_default(void)
#endif
#if CONFIG_SYSVIEW_ENABLE
SEGGER_SYSVIEW_Conf();
#endif
#if CONFIG_ESP32_DEBUG_STUBS_ENABLE
esp_dbg_stubs_init();
#endif
err = esp_pthread_init();
assert(err == ESP_OK && "Failed to init pthread module!");

View File

@@ -0,0 +1,95 @@
// Copyright 2017 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.
// This module implements debug/trace stubs. The stub is a piece of special code which can invoked by OpenOCD
// Currently one stub is used for GCOV functionality
//
#include "eri.h"
#include "xtensa-debug-module.h"
#include "esp_dbg_stubs.h"
#include "esp_attr.h"
#if CONFIG_ESP32_DEBUG_STUBS_ENABLE
/*
Debug stubs is actually a table of 4-byte entries. Every entry is equal to zero or must contain meaningfull data.
The first entry is a service one and has the followinf format:
- tramp_addr, 4 bytes; Address of buffer for trampoline/code. Max size is ESP_DBG_STUBS_CODE_BUF_SIZE.
- min_stack_addr, 4 bytes; Start of the buffer for minimal onboard stack or data. Max size is ESP_DBG_STUBS_STACK_MIN_SIZE.
- data_alloc, 4 bytes; Address of function to allocate memory on target.
- data_free, 4 bytes; Address of function to free target memory.
This entry is used by OpenOCD code to invoke other stub entries and allocate memory for them.
*/
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include "esp_log.h"
const static char *TAG = "esp_dbg_stubs";
#define ESP_DBG_STUBS_TRAX_REG ERI_TRAX_TRIGGERPC
#define ESP_DBG_STUBS_CODE_BUF_SIZE 32
#define ESP_DBG_STUBS_STACK_MIN_SIZE 2048
#define DBG_STUB_TRAMP_ATTR IRAM_ATTR
static struct {
uint32_t tramp_addr;
uint32_t min_stack_addr; // minimal stack addr
uint32_t data_alloc;
uint32_t data_free;
} s_dbg_stubs_ctl_data;
static uint32_t s_stub_entry[ESP_DBG_STUB_ENTRY_MAX];
static uint8_t s_stub_min_stack[ESP_DBG_STUBS_STACK_MIN_SIZE];
static DBG_STUB_TRAMP_ATTR uint8_t s_stub_code_buf[ESP_DBG_STUBS_CODE_BUF_SIZE];
// TODO: all called funcs should be in IRAM to work with disabled flash cache
static void * esp_dbg_stubs_data_alloc(uint32_t size)
{
ESP_LOGV(TAG, "%s %d", __func__, size);
void *p = malloc(size);
ESP_LOGV(TAG, "%s EXIT %p", __func__, p);
return p;
}
static void esp_dbg_stubs_data_free(void *addr)
{
ESP_LOGV(TAG, "%s %p", __func__, addr);
free(addr);
ESP_LOGV(TAG, "%s EXIT %p", __func__, addr);
}
void esp_dbg_stubs_init()
{
s_dbg_stubs_ctl_data.tramp_addr = (uint32_t)s_stub_code_buf;
s_dbg_stubs_ctl_data.min_stack_addr = (uint32_t)s_stub_min_stack;
s_dbg_stubs_ctl_data.data_alloc = (uint32_t)esp_dbg_stubs_data_alloc;
s_dbg_stubs_ctl_data.data_free = (uint32_t)esp_dbg_stubs_data_free;
s_stub_entry[ESP_DBG_STUB_CONTROL_DATA] = (uint32_t)&s_dbg_stubs_ctl_data;
eri_write(ESP_DBG_STUBS_TRAX_REG, (uint32_t)s_stub_entry);
ESP_LOGV(TAG, "%s stubs %x", __func__, eri_read(ESP_DBG_STUBS_TRAX_REG));
}
esp_err_t esp_dbg_stub_entry_set(esp_dbg_stub_id_t id, uint32_t entry)
{
if (id < ESP_DBG_STUB_ENTRY_FIRST || id >= ESP_DBG_STUB_ENTRY_MAX) {
ESP_LOGE(TAG, "Invalid stub id %d!", id);
return ESP_ERR_INVALID_ARG;
}
s_stub_entry[id] = entry;
return ESP_OK;
}
#endif

View File

@@ -217,3 +217,96 @@ void IRAM_ATTR esp_dport_access_int_resume(void)
#endif
}
/**
* @brief Read a sequence of DPORT registers to the buffer, SMP-safe version.
*
* This implementation uses a method of the pre-reading of the APB register
* before reading the register of the DPORT, without stall other CPU.
* There is disable/enable interrupt.
*
* @param[out] buff_out Contains the read data.
* @param[in] address Initial address for reading registers.
* @param[in] num_words The number of words.
*/
void IRAM_ATTR esp_dport_access_read_buffer(uint32_t *buff_out, uint32_t address, uint32_t num_words)
{
DPORT_INTERRUPT_DISABLE();
for (uint32_t i = 0; i < num_words; ++i) {
buff_out[i] = DPORT_SEQUENCE_REG_READ(address + i * 4);
}
DPORT_INTERRUPT_RESTORE();
}
/**
* @brief Read value from register, SMP-safe version.
*
* This method uses the pre-reading of the APB register before reading the register of the DPORT.
* This implementation is useful for reading DORT registers for single reading without stall other CPU.
* There is disable/enable interrupt.
*
* @param reg Register address
* @return Value
*/
uint32_t IRAM_ATTR esp_dport_access_reg_read(uint32_t reg)
{
#if defined(BOOTLOADER_BUILD) || defined(CONFIG_FREERTOS_UNICORE) || !defined(ESP_PLATFORM)
return _DPORT_REG_READ(reg);
#else
uint32_t apb;
unsigned int intLvl;
__asm__ __volatile__ (\
"movi %[APB], "XTSTR(0x3ff40078)"\n"\
"rsil %[LVL], "XTSTR(3)"\n"\
"l32i %[APB], %[APB], 0\n"\
"l32i %[REG], %[REG], 0\n"\
"wsr %[LVL], "XTSTR(PS)"\n"\
"rsync\n"\
: [APB]"=a"(apb), [REG]"+a"(reg), [LVL]"=a"(intLvl)\
: \
: "memory" \
);
return reg;
#endif
}
/**
* @brief Read value from register, NOT SMP-safe version.
*
* This method uses the pre-reading of the APB register before reading the register of the DPORT.
* There is not disable/enable interrupt.
* The difference from DPORT_REG_READ() is that the user himself must disable interrupts while DPORT reading.
* This implementation is useful for reading DORT registers in loop without stall other CPU. Note the usage example.
* The recommended way to read registers sequentially without stall other CPU
* is to use the method esp_dport_read_buffer(buff_out, address, num_words). It allows you to read registers in the buffer.
*
* \code{c}
* // This example shows how to use it.
* { // Use curly brackets to limit the visibility of variables in macros DPORT_INTERRUPT_DISABLE/RESTORE.
* DPORT_INTERRUPT_DISABLE(); // Disable interrupt only on current CPU.
* for (i = 0; i < max; ++i) {
* array[i] = esp_dport_access_sequence_reg_read(Address + i * 4); // reading DPORT registers
* }
* DPORT_INTERRUPT_RESTORE(); // restore the previous interrupt level
* }
* \endcode
*
* @param reg Register address
* @return Value
*/
uint32_t IRAM_ATTR esp_dport_access_sequence_reg_read(uint32_t reg)
{
#if defined(BOOTLOADER_BUILD) || defined(CONFIG_FREERTOS_UNICORE) || !defined(ESP_PLATFORM)
return _DPORT_REG_READ(reg);
#else
uint32_t apb;
__asm__ __volatile__ (\
"movi %[APB], "XTSTR(0x3ff40078)"\n"\
"l32i %[APB], %[APB], 0\n"\
"l32i %[REG], %[REG], 0\n"\
: [APB]"=a"(apb), [REG]"+a"(reg)\
: \
: "memory" \
);
return reg;
#endif
}

View File

@@ -10,6 +10,9 @@
#if __has_include("esp_err.h")
#include "esp_err.h"
#endif
#if __has_include("esp_http_client.h")
#include "esp_http_client.h"
#endif
#if __has_include("esp_image_format.h")
#include "esp_image_format.h"
#endif
@@ -359,6 +362,9 @@ static const esp_err_msg_t esp_err_msg_table[] = {
# endif
# ifdef ESP_ERR_MESH_DISCARD
ERR_TBL_IT(ESP_ERR_MESH_DISCARD), /* 16405 0x4015 */
# endif
# ifdef ESP_ERR_MESH_VOTING
ERR_TBL_IT(ESP_ERR_MESH_VOTING), /* 16406 0x4016 */
# endif
// components/tcpip_adapter/include/tcpip_adapter.h
# ifdef ESP_ERR_TCPIP_ADAPTER_BASE
@@ -394,6 +400,26 @@ static const esp_err_msg_t esp_err_msg_table[] = {
# endif
# ifdef ESP_ERR_PING_NO_MEM
ERR_TBL_IT(ESP_ERR_PING_NO_MEM), /* 24578 0x6002 */
# endif
// components/esp_http_client/include/esp_http_client.h
# ifdef ESP_ERR_HTTP_BASE
ERR_TBL_IT(ESP_ERR_HTTP_BASE), /* 28672 0x7000 Starting number of HTTP error codes */
# endif
# ifdef ESP_ERR_HTTP_MAX_REDIRECT
ERR_TBL_IT(ESP_ERR_HTTP_MAX_REDIRECT), /* 28673 0x7001 The error exceeds the number of HTTP redirects */
# endif
# ifdef ESP_ERR_HTTP_CONNECT
ERR_TBL_IT(ESP_ERR_HTTP_CONNECT), /* 28674 0x7002 Error open the HTTP connection */
# endif
# ifdef ESP_ERR_HTTP_WRITE_DATA
ERR_TBL_IT(ESP_ERR_HTTP_WRITE_DATA), /* 28675 0x7003 Error write HTTP data */
# endif
# ifdef ESP_ERR_HTTP_FETCH_HEADER
ERR_TBL_IT(ESP_ERR_HTTP_FETCH_HEADER), /* 28676 0x7004 Error read HTTP header from server */
# endif
# ifdef ESP_ERR_HTTP_INVALID_TRANSPORT
ERR_TBL_IT(ESP_ERR_HTTP_INVALID_TRANSPORT), /* 28677 0x7005 There are no transport support for the input
scheme */
# endif
// components/spi_flash/include/esp_spi_flash.h
# ifdef ESP_ERR_FLASH_BASE

View File

@@ -467,6 +467,18 @@ esp_err_t esp_timer_dump(FILE* stream)
return ESP_OK;
}
int64_t IRAM_ATTR esp_timer_get_next_alarm()
{
int64_t next_alarm = INT64_MAX;
timer_list_lock();
esp_timer_handle_t it = LIST_FIRST(&s_timers);
if (it) {
next_alarm = it->alarm;
}
timer_list_unlock();
return next_alarm;
}
int64_t IRAM_ATTR esp_timer_get_time()
{
return (int64_t) esp_timer_impl_get_time();

View File

@@ -165,6 +165,16 @@ static inline void IRAM_ATTR timer_count_reload(void)
REG_WRITE(FRC_TIMER_LOAD_REG(1), REG_READ(FRC_TIMER_COUNT_REG(1)) - ALARM_OVERFLOW_VAL);
}
void esp_timer_impl_lock()
{
portENTER_CRITICAL(&s_time_update_lock);
}
void esp_timer_impl_unlock()
{
portEXIT_CRITICAL(&s_time_update_lock);
}
uint64_t IRAM_ATTR esp_timer_impl_get_time()
{
uint32_t timer_val;
@@ -311,6 +321,22 @@ void IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
portEXIT_CRITICAL_ISR(&s_time_update_lock);
}
void esp_timer_impl_advance(int64_t time_us)
{
assert(time_us > 0 && "negative adjustments not supported yet");
portENTER_CRITICAL(&s_time_update_lock);
uint64_t count = REG_READ(FRC_TIMER_COUNT_REG(1));
/* Trigger an ISR to handle past alarms and set new one.
* ISR handler will run once we exit the critical section.
*/
REG_WRITE(FRC_TIMER_ALARM_REG(1), 0);
REG_WRITE(FRC_TIMER_LOAD_REG(1), 0);
s_time_base_us += count / s_timer_ticks_per_us + time_us;
s_overflow_happened = false;
portEXIT_CRITICAL(&s_time_update_lock);
}
esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
{
s_alarm_handler = alarm_handler;

View File

@@ -60,6 +60,15 @@ void esp_timer_impl_set_alarm(uint64_t timestamp);
*/
void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us);
/**
* @brief Adjust current esp_timer time by a certain value
*
* Called from light sleep code to synchronize esp_timer time with RTC time.
*
* @param time_us adjustment to apply to esp_timer time, in microseconds
*/
void esp_timer_impl_advance(int64_t time_us);
/**
* @brief Get time, in microseconds, since esp_timer_impl_init was called
* @return timestamp in microseconds
@@ -75,3 +84,18 @@ uint64_t esp_timer_impl_get_time();
* @return minimal period of periodic timer, in microseconds
*/
uint64_t esp_timer_impl_get_min_period_us();
/**
* @brief obtain internal critical section used esp_timer implementation
* This can be used when a sequence of calls to esp_timer has to be made,
* and it is necessary that the state of the timer is consistent between
* the calls. Should be treated in the same way as a spinlock.
* Call esp_timer_impl_unlock to release the lock
*/
void esp_timer_impl_lock();
/**
* @brief counterpart of esp_timer_impl_lock
*/
void esp_timer_impl_unlock();

View File

@@ -334,6 +334,10 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
MAC2STR(stadisconnected->mac), stadisconnected->aid);
break;
}
case SYSTEM_EVENT_AP_STAIPASSIGNED: {
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STAIPASSIGNED");
break;
}
case SYSTEM_EVENT_AP_PROBEREQRECVED: {
system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved;
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \

View File

@@ -16,8 +16,18 @@
#include "crypto/aes_wrap.h"
#include "crypto/sha256.h"
#include "crypto/crypto.h"
#include "crypto/md5.h"
#include "crypto/sha1.h"
#include "crypto/aes.h"
#include "crypto/dh_group5.h"
#include "wps/wps.h"
#include "wps/wps_i.h"
#include "wpa2/eap_peer/eap.h"
#include "wpa2/tls/tls.h"
#include "wpa2/eap_peer/eap_methods.h"
#include "wpa2/eap_peer/eap_i.h"
#include "wpa2/eap_peer/eap_common.h"
#include "esp_wifi_crypto_types.h"
/*
* The parameters is used to set the cyrpto callback function for station connect when in security mode,
* every callback function can register as fast_xxx or normal one, i.e, fast_aes_wrap or aes_wrap, the
@@ -29,7 +39,22 @@ const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
.aes_wrap = (esp_aes_wrap_t)fast_aes_wrap,
.aes_unwrap = (esp_aes_unwrap_t)fast_aes_unwrap,
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector,
.sha256_prf = (esp_sha256_prf_t)fast_sha256_prf
.sha256_prf = (esp_sha256_prf_t)fast_sha256_prf,
.hmac_md5 = (esp_hmac_md5_t)hmac_md5,
.hamc_md5_vector = (esp_hmac_md5_vector_t)hmac_md5_vector,
.hmac_sha1 = (esp_hmac_sha1_t)hmac_sha1,
.hmac_sha1_vector = (esp_hmac_sha1_vector_t)hmac_sha1_vector,
.sha1_prf = (esp_sha1_prf_t)sha1_prf,
.sha1_vector = (esp_sha1_vector_t)sha1_vector,
.pbkdf2_sha1 = (esp_pbkdf2_sha1_t)pbkdf2_sha1,
.rc4_skip = (esp_rc4_skip_t)rc4_skip,
.md5_vector = (esp_md5_vector_t)md5_vector,
.aes_encrypt = (esp_aes_encrypt_t)aes_encrypt,
.aes_encrypt_init = (esp_aes_encrypt_init_t)aes_encrypt_init,
.aes_encrypt_deinit = (esp_aes_encrypt_deinit_t)aes_encrypt_deinit,
.aes_decrypt = (esp_aes_decrypt_t)aes_decrypt,
.aes_decrypt_init = (esp_aes_decrypt_init_t)aes_decrypt_init,
.aes_decrypt_deinit = (esp_aes_decrypt_deinit_t)aes_decrypt_deinit
};
const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
@@ -38,7 +63,19 @@ const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
.crypto_mod_exp = (esp_crypto_mod_exp_t)fast_crypto_mod_exp,
.hmac_sha256 = (esp_hmac_sha256_t)fast_hmac_sha256,
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector,
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector,
.uuid_gen_mac_addr = (esp_uuid_gen_mac_addr_t)uuid_gen_mac_addr,
.dh5_free = (esp_dh5_free_t)dh5_free,
.wps_build_assoc_req_ie = (esp_wps_build_assoc_req_ie_t)wps_build_assoc_req_ie,
.wps_build_assoc_resp_ie = (esp_wps_build_assoc_resp_ie_t)wps_build_assoc_resp_ie,
.wps_build_probe_req_ie = (esp_wps_build_probe_req_ie_t)wps_build_probe_req_ie,
.wps_build_public_key = (esp_wps_build_public_key_t)wps_build_public_key,
.wps_enrollee_get_msg = (esp_wps_enrollee_get_msg_t)wps_enrollee_get_msg,
.wps_enrollee_process_msg = (esp_wps_enrollee_process_msg_t)wps_enrollee_process_msg,
.wps_generate_pin = (esp_wps_generate_pin_t)wps_generate_pin,
.wps_is_selected_pin_registrar = (esp_wps_is_selected_pin_registrar_t)wps_is_selected_pin_registrar,
.wps_is_selected_pbc_registrar = (esp_wps_is_selected_pbc_registrar_t)wps_is_selected_pbc_registrar,
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
};
/*
@@ -56,7 +93,19 @@ const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs = {
.crypto_cipher_decrypt = (esp_crypto_cipher_decrypt_t)fast_crypto_cipher_decrypt,
.crypto_cipher_deinit = (esp_crypto_cipher_deinit_t)fast_crypto_cipher_deinit,
.crypto_mod_exp = (esp_crypto_mod_exp_t)crypto_mod_exp,
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector,
.tls_init = (esp_tls_init_t)tls_init,
.tls_deinit = (esp_tls_deinit_t)tls_deinit,
.eap_peer_blob_init = (esp_eap_peer_blob_init_t)eap_peer_blob_init,
.eap_peer_blob_deinit = (esp_eap_peer_blob_deinit_t)eap_peer_blob_deinit,
.eap_peer_config_init = (esp_eap_peer_config_init_t)eap_peer_config_init,
.eap_peer_config_deinit = (esp_eap_peer_config_deinit_t)eap_peer_config_deinit,
.eap_deinit_prev_method = (esp_eap_deinit_prev_method_t)eap_deinit_prev_method,
.eap_peer_get_eap_method = (esp_eap_peer_get_eap_method_t)eap_peer_get_eap_method,
.eap_sm_abort = (esp_eap_sm_abort_t)eap_sm_abort,
.eap_sm_build_nak = (esp_eap_sm_build_nak_t)eap_sm_build_nak,
.eap_sm_build_identity_resp = (esp_eap_sm_build_identity_resp_t)eap_sm_build_identity_resp,
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
};
const mesh_crypto_funcs_t g_wifi_default_mesh_crypto_funcs = {

View File

@@ -59,6 +59,10 @@ void esp_vApplicationIdleHook()
#ifdef CONFIG_PM_ENABLE
esp_pm_impl_idle_hook();
#endif
}
extern void esp_vApplicationWaitiHook( void )
{
asm("waiti 0");
}

View File

@@ -53,31 +53,23 @@ void esp_aes_acquire_hardware( void )
/* newlib locks lazy initialize on ESP-IDF */
portENTER_CRITICAL(&aes_spinlock);
DPORT_STALL_OTHER_CPU_START();
{
/* Enable AES hardware */
_DPORT_REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_AES);
/* Clear reset on digital signature & secure boot units,
otherwise AES unit is held in reset also. */
_DPORT_REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
DPORT_PERI_EN_AES
| DPORT_PERI_EN_DIGITAL_SIGNATURE
| DPORT_PERI_EN_SECUREBOOT);
}
DPORT_STALL_OTHER_CPU_END();
/* Enable AES hardware */
DPORT_REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_AES);
/* Clear reset on digital signature & secure boot units,
otherwise AES unit is held in reset also. */
DPORT_REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
DPORT_PERI_EN_AES
| DPORT_PERI_EN_DIGITAL_SIGNATURE
| DPORT_PERI_EN_SECUREBOOT);
}
void esp_aes_release_hardware( void )
{
DPORT_STALL_OTHER_CPU_START();
{
/* Disable AES hardware */
_DPORT_REG_SET_BIT(DPORT_PERI_RST_EN_REG, DPORT_PERI_EN_AES);
/* Don't return other units to reset, as this pulls
reset on RSA & SHA units, respectively. */
_DPORT_REG_CLR_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_AES);
}
DPORT_STALL_OTHER_CPU_END();
/* Disable AES hardware */
DPORT_REG_SET_BIT(DPORT_PERI_RST_EN_REG, DPORT_PERI_EN_AES);
/* Don't return other units to reset, as this pulls
reset on RSA & SHA units, respectively. */
DPORT_REG_CLR_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_AES);
portEXIT_CRITICAL(&aes_spinlock);
}
@@ -141,21 +133,14 @@ static inline void esp_aes_block(const void *input, void *output)
}
DPORT_REG_WRITE(AES_START_REG, 1);
DPORT_STALL_OTHER_CPU_START();
{
while (_DPORT_REG_READ(AES_IDLE_REG) != 1) { }
for (int i = 0; i < 4; i++) {
output_words[i] = mem_block[i];
}
}
DPORT_STALL_OTHER_CPU_END();
while (DPORT_REG_READ(AES_IDLE_REG) != 1) { }
esp_dport_access_read_buffer(output_words, (uint32_t)&mem_block[0], 4);
}
/*
* AES-ECB block encryption
*/
void esp_aes_encrypt( esp_aes_context *ctx,
int esp_internal_aes_encrypt( esp_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
@@ -163,13 +148,21 @@ void esp_aes_encrypt( esp_aes_context *ctx,
esp_aes_setkey_hardware(ctx, ESP_AES_ENCRYPT);
esp_aes_block(input, output);
esp_aes_release_hardware();
return 0;
}
void esp_aes_encrypt( esp_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
esp_internal_aes_encrypt(ctx, input, output);
}
/*
* AES-ECB block decryption
*/
void esp_aes_decrypt( esp_aes_context *ctx,
int esp_internal_aes_decrypt( esp_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
@@ -177,6 +170,14 @@ void esp_aes_decrypt( esp_aes_context *ctx,
esp_aes_setkey_hardware(ctx, ESP_AES_DECRYPT);
esp_aes_block(input, output);
esp_aes_release_hardware();
return 0;
}
void esp_aes_decrypt( esp_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
esp_internal_aes_decrypt(ctx, input, output);
}

View File

@@ -159,16 +159,14 @@ static void esp_sha_lock_engine_inner(sha_engine_state *engine)
_lock_acquire(&state_change_lock);
if (sha_engines_all_idle()) {
/* Enable SHA hardware */
DPORT_REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_SHA);
/* also clear reset on secure boot, otherwise SHA is held in reset */
DPORT_REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
DPORT_PERI_EN_SHA
| DPORT_PERI_EN_SECUREBOOT);
DPORT_STALL_OTHER_CPU_START();
{
/* Enable SHA hardware */
_DPORT_REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_SHA);
/* also clear reset on secure boot, otherwise SHA is held in reset */
_DPORT_REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
DPORT_PERI_EN_SHA
| DPORT_PERI_EN_SECUREBOOT);
ets_sha_enable();
}
ets_sha_enable();
DPORT_STALL_OTHER_CPU_END();
}
@@ -191,12 +189,8 @@ void esp_sha_unlock_engine(esp_sha_type sha_type)
if (sha_engines_all_idle()) {
/* Disable SHA hardware */
/* Don't assert reset on secure boot, otherwise AES is held in reset */
DPORT_STALL_OTHER_CPU_START();
{
_DPORT_REG_SET_BIT(DPORT_PERI_RST_EN_REG, DPORT_PERI_EN_SHA);
_DPORT_REG_CLR_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_SHA);
}
DPORT_STALL_OTHER_CPU_END();
DPORT_REG_SET_BIT(DPORT_PERI_RST_EN_REG, DPORT_PERI_EN_SHA);
DPORT_REG_CLR_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_SHA);
}
_lock_release(&state_change_lock);
@@ -206,16 +200,14 @@ void esp_sha_unlock_engine(esp_sha_type sha_type)
void esp_sha_wait_idle(void)
{
DPORT_STALL_OTHER_CPU_START();
while(1) {
if(_DPORT_REG_READ(SHA_1_BUSY_REG) == 0
&& _DPORT_REG_READ(SHA_256_BUSY_REG) == 0
&& _DPORT_REG_READ(SHA_384_BUSY_REG) == 0
&& _DPORT_REG_READ(SHA_512_BUSY_REG) == 0) {
if(DPORT_REG_READ(SHA_1_BUSY_REG) == 0
&& DPORT_REG_READ(SHA_256_BUSY_REG) == 0
&& DPORT_REG_READ(SHA_384_BUSY_REG) == 0
&& DPORT_REG_READ(SHA_512_BUSY_REG) == 0) {
break;
}
}
DPORT_STALL_OTHER_CPU_END();
}
void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state)
@@ -225,27 +217,23 @@ void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state)
esp_sha_lock_memory_block();
DPORT_STALL_OTHER_CPU_START(); // This block reads from DPORT memory (reg_addr_buf)
{
esp_sha_wait_idle();
esp_sha_wait_idle();
_DPORT_REG_WRITE(SHA_LOAD_REG(sha_type), 1);
while(_DPORT_REG_READ(SHA_BUSY_REG(sha_type)) == 1) { }
uint32_t *digest_state_words = (uint32_t *)digest_state;
uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
if(sha_type == SHA2_384 || sha_type == SHA2_512) {
/* for these ciphers using 64-bit states, swap each pair of words */
for(int i = 0; i < sha_length(sha_type)/4; i += 2) {
digest_state_words[i+1] = reg_addr_buf[i];
digest_state_words[i]= reg_addr_buf[i+1];
}
} else {
memcpy(digest_state_words, reg_addr_buf, sha_length(sha_type));
DPORT_REG_WRITE(SHA_LOAD_REG(sha_type), 1);
while(DPORT_REG_READ(SHA_BUSY_REG(sha_type)) == 1) { }
uint32_t *digest_state_words = (uint32_t *)digest_state;
uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
if(sha_type == SHA2_384 || sha_type == SHA2_512) {
/* for these ciphers using 64-bit states, swap each pair of words */
DPORT_INTERRUPT_DISABLE(); // Disable interrupt only on current CPU.
for(int i = 0; i < sha_length(sha_type)/4; i += 2) {
digest_state_words[i+1] = DPORT_SEQUENCE_REG_READ((uint32_t)&reg_addr_buf[i]);
digest_state_words[i] = DPORT_SEQUENCE_REG_READ((uint32_t)&reg_addr_buf[i+1]);
}
DPORT_INTERRUPT_RESTORE(); // restore the previous interrupt level
} else {
esp_dport_access_read_buffer(digest_state_words, (uint32_t)&reg_addr_buf[0], sha_length(sha_type)/4);
}
DPORT_STALL_OTHER_CPU_END();
esp_sha_unlock_memory_block();
}

View File

@@ -0,0 +1,50 @@
// Copyright 2017 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 ESP_DBG_STUBS_H_
#define ESP_DBG_STUBS_H_
#include "esp_err.h"
/**
* Debug stubs entries IDs
*/
typedef enum {
ESP_DBG_STUB_CONTROL_DATA, ///< stubs descriptor entry
ESP_DBG_STUB_ENTRY_FIRST,
ESP_DBG_STUB_ENTRY_GCOV ///< GCOV entry
= ESP_DBG_STUB_ENTRY_FIRST,
ESP_DBG_STUB_ENTRY_MAX
} esp_dbg_stub_id_t;
/**
* @brief Initializes debug stubs.
*
* @note Must be called after esp_apptrace_init() if app tracing is enabled.
*/
void esp_dbg_stubs_init(void);
/**
* @brief Initializes application tracing module.
*
* @note Should be called before any esp_apptrace_xxx call.
*
* @param id Stub ID.
* @param entry Stub entry. Usually it is stub entry function address,
* but can be any value meaningfull for OpenOCD command/code.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_dbg_stub_entry_set(esp_dbg_stub_id_t id, uint32_t entry);
#endif //ESP_DBG_STUBS_H_

View File

@@ -26,7 +26,9 @@ void esp_dport_access_stall_other_cpu_end(void);
void esp_dport_access_int_init(void);
void esp_dport_access_int_pause(void);
void esp_dport_access_int_resume(void);
void esp_dport_access_read_buffer(uint32_t *buff_out, uint32_t address, uint32_t num_words);
uint32_t esp_dport_access_reg_read(uint32_t reg);
uint32_t esp_dport_access_sequence_reg_read(uint32_t reg);
//This routine does not stop the dport routines in any way that is recoverable. Please
//only call in case of panic().
void esp_dport_access_int_abort(void);
@@ -34,9 +36,13 @@ void esp_dport_access_int_abort(void);
#if defined(BOOTLOADER_BUILD) || defined(CONFIG_FREERTOS_UNICORE) || !defined(ESP_PLATFORM)
#define DPORT_STALL_OTHER_CPU_START()
#define DPORT_STALL_OTHER_CPU_END()
#define DPORT_INTERRUPT_DISABLE()
#define DPORT_INTERRUPT_RESTORE()
#else
#define DPORT_STALL_OTHER_CPU_START() esp_dport_access_stall_other_cpu_start()
#define DPORT_STALL_OTHER_CPU_END() esp_dport_access_stall_other_cpu_end()
#define DPORT_INTERRUPT_DISABLE() unsigned int intLvl = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL)
#define DPORT_INTERRUPT_RESTORE() XTOS_RESTORE_JUST_INTLEVEL(intLvl)
#endif
#ifdef __cplusplus

View File

@@ -44,6 +44,7 @@ typedef enum {
SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP32 soft-AP assign an IP to a connected station */
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */

View File

@@ -68,7 +68,7 @@
*
* In present implementation, applications are able to access mesh stack directly without having to go through LwIP stack.
* Applications use esp_mesh_send() and esp_mesh_recv() to send and receive messages over the mesh network.
* In mesh stack design, normal nodes don't require LwIP stack. But since IDF hasn't supported system without initializing LwIP stack yet,
* In mesh stack design, normal devices don't require LwIP stack. But since IDF hasn't supported system without initializing LwIP stack yet,
* applications still need to do LwIP initialization and two more things are required to be done
* (1)stop DHCP server on softAP interface by default
* (2)stop DHCP client on station interface by default.
@@ -78,7 +78,7 @@
* tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA)
*
* Over the mesh network, only root is able to access external IP network.
* In application mesh event handler, once a node becomes a root, start DHCP client immediately if DHCP is chosen.
* In application mesh event handler, once a device becomes a root, start DHCP client immediately if DHCP is chosen.
*/
#ifndef __ESP_MESH_H__
@@ -123,6 +123,7 @@ extern "C" {
#define ESP_ERR_MESH_INTERFACE (ESP_ERR_MESH_BASE + 19) /**< low-level WiFi interface error */
#define ESP_ERR_MESH_DISCARD_DUPLICATE (ESP_ERR_MESH_BASE + 20) /**< discard the packet due to the duplicate sequence number */
#define ESP_ERR_MESH_DISCARD (ESP_ERR_MESH_BASE + 21) /**< discard the packet */
#define ESP_ERR_MESH_VOTING (ESP_ERR_MESH_BASE + 22) /**< vote in progress */
/**
* @brief flags used with esp_mesh_send() and esp_mesh_recv()
@@ -138,9 +139,17 @@ extern "C" {
/**
* @brief option definitions for esp_mesh_send() and esp_mesh_recv()
*/
#define MESH_OPT_SEND_GROUP (7) /**< data transmission by group; used with esp_mesh_send() and must have payload */
#define MESH_OPT_SEND_GROUP (7) /**< data transmission by group; used with esp_mesh_send() and shall have payload */
#define MESH_OPT_RECV_DS_ADDR (8) /**< return a remote IP address; used with esp_mesh_send() and esp_mesh_recv() */
/**
* @brief flag of mesh networking IE
*/
#define MESH_ASSOC_FLAG_VOTE_IN_PROGRESS (0x02) /**< vote in progress */
#define MESH_ASSOC_FLAG_NETWORK_FREE (0x08) /**< no root in current network */
#define MESH_ASSOC_FLAG_ROOTS_FOUND (0x20) /**< root conflict is found */
#define MESH_ASSOC_FLAG_ROOT_FIXED (0x40) /**< root is fixed */
/*******************************************************
* Enumerations
*******************************************************/
@@ -171,19 +180,21 @@ typedef enum {
and this device is specified to be a root by users, users should set a new parent
for this device. if self organized is enabled, this device will find a new parent
by itself, users could ignore this event. */
MESH_EVENT_ROOT_FIXED, /**< When nodes join a network, if the setting of Root Fixed for one node is different
from that of its parent, the node will update the setting the same as its parent's.
Root Fixed setting of each node is variable as that setting changes of root. */
MESH_EVENT_ROOT_FIXED, /**< when devices join a network, if the setting of Fixed Root for one device is different
from that of its parent, the device will update the setting the same as its parent's.
Fixed Root setting of each device is variable as that setting changes of root. */
MESH_EVENT_SCAN_DONE, /**< if self-organized networking is disabled, user can call esp_wifi_scan_start() to trigger
this event, and add the corresponding scan done handler in this event. */
MESH_EVENT_MAX,
} mesh_event_id_t;
/**
* @brief node type
* @brief device type
*/
typedef enum {
MESH_IDLE, /**< hasn't joined the mesh network yet */
MESH_ROOT, /**< the only sink of the mesh network. Has the ability to access external IP network */
MESH_NODE, /**< intermediate node. Has the ability to forward packets over the mesh network */
MESH_NODE, /**< intermediate device. Has the ability to forward packets over the mesh network */
MESH_LEAF, /**< has no forwarding ability */
} mesh_type_t;
@@ -220,7 +231,7 @@ typedef enum {
typedef enum {
MESH_REASON_CYCLIC = 100, /**< cyclic is detected */
MESH_REASON_PARENT_IDLE, /**< parent is idle */
MESH_REASON_LEAF, /**< the connected node is changed to a leaf */
MESH_REASON_LEAF, /**< the connected device is changed to a leaf */
MESH_REASON_DIFF_ID, /**< in different mesh ID */
MESH_REASON_ROOTS, /**< root conflict is detected */
MESH_REASON_PARENT_STOPPED, /**< parent has stopped the mesh */
@@ -330,7 +341,7 @@ typedef struct {
*/
typedef struct {
int8_t rssi; /**< rssi with router */
uint16_t capacity; /**< the number of nodes in its network */
uint16_t capacity; /**< the number of devices in current network */
uint8_t addr[6]; /**< other powerful root address */
} mesh_event_root_conflict_t;
@@ -349,6 +360,13 @@ typedef struct {
bool is_fixed; /**< status */
} mesh_event_root_fixed_t;
/**
* @brief scan done event information
*/
typedef struct {
uint8_t number; /**< the number of scanned APs */
} mesh_event_scan_done_t;
/**
* @brief mesh event information
*/
@@ -361,16 +379,17 @@ typedef union {
mesh_event_disconnected_t disconnected; /**< parent disconnected */
mesh_event_no_parent_found_t no_parent; /**< no parent found */
mesh_event_layer_change_t layer_change; /**< layer change */
mesh_event_toDS_state_t toDS_state; /**< toDS state, nodes should check this state firstly before trying to send packets to
external IP network. This state indicates right now if root is capable
of sending packets out. If not, nodes had better to wait until this state changes
to be MESH_TODS_REACHABLE. */
mesh_event_toDS_state_t toDS_state; /**< toDS state, devices shall check this state firstly before trying to send packets to
external IP network. This state indicates right now if root is capable of sending
packets out. If not, devices had better to wait until this state changes to be
MESH_TODS_REACHABLE. */
mesh_event_vote_started_t vote_started; /**< vote started */
mesh_event_root_got_ip_t got_ip; /**< root obtains IP address */
mesh_event_root_address_t root_addr; /**< root address */
mesh_event_root_switch_req_t switch_req; /**< root switch request */
mesh_event_root_conflict_t root_conflict; /**< other powerful root */
mesh_event_root_fixed_t root_fixed; /**< root fixed */
mesh_event_scan_done_t scan_done; /**< scan done */
} mesh_event_info_t;
/**
@@ -438,11 +457,21 @@ typedef struct {
} mesh_cfg_t;
/**
* @brief vote
* @brief vote address configuration
*/
typedef union {
int attempts; /**< max vote attempts */
mesh_addr_t rc_addr; /**< root address specified by users for API esp_mesh_waive_root() */
int attempts; /**< max vote attempts before a new root is elected automatically by mesh network. (min:15, 15 by default) */
mesh_addr_t rc_addr; /**< a new root address specified by users for API esp_mesh_waive_root() */
} mesh_rc_config_t;
/**
* @brief vote
*/
typedef struct {
float percentage; /**< vote percentage threshold for approval of being a root */
bool is_rc_specified; /**< if true, rc_addr shall be specified(Unimplemented).
if false, attempts value shall be specified to make network start root election. */
mesh_rc_config_t config; /**< vote address configuration */
} mesh_vote_t;
/**
@@ -486,7 +515,7 @@ extern mesh_event_cb_t g_mesh_event_cb;
* Check if WiFi is started.
* Initialize mesh global variables with default values.
*
* @attention This API should be called after WiFi is started.
* @attention This API shall be called after WiFi is started.
*
* @return
* - ESP_OK
@@ -511,7 +540,7 @@ esp_err_t esp_mesh_deinit(void);
* Create TX and RX queues according to the configuration
* Register mesh packets receive callback
*
* @attention This API should be called after esp_mesh_init() and esp_mesh_set_config().
* @attention This API shall be called after esp_mesh_init() and esp_mesh_set_config().
*
* @return
* - ESP_OK
@@ -541,7 +570,7 @@ esp_err_t esp_mesh_stop(void);
/**
* @brief send a packet over the mesh network
* Send a packet to any node in the mesh network.
* Send a packet to any device in the mesh network.
* Send a packet to external IP network.
*
* @attention This API is not reentrant.
@@ -555,9 +584,9 @@ esp_err_t esp_mesh_stop(void);
* Should specify the transmission tos(type of service), P2P reliable by default.
* @param flag
* (1)used to speed up the route selection
* if the packet is target to an internal node, MESH_DATA_P2P should be set.
* if the packet is target to an internal device, MESH_DATA_P2P should be set.
* if the packet is outgoing to root or to external IP network, MESH_DATA_TODS should be set.
* if the packet is from root to an internal node, MESH_DATA_FROMDS should be set.
* if the packet is from root to an internal device, MESH_DATA_FROMDS should be set.
* (2)specify if this API is block or non-block, block by default
* if needs non-block, MESH_DATA_NONBLOCK should be set.
* (3)in the situation of root having been changed, MESH_DATA_DROP identifies this packet can be dropped by new root
@@ -570,7 +599,7 @@ esp_err_t esp_mesh_stop(void);
* @param opt options
* (1)in case of sending a packet to a specified group, MESH_OPT_SEND_GROUP is a good choice.
* In this option, the value field should specify the target receiver addresses in this group.
* (2)root sends a packet to an internal node, this packet is from external IP network in case the receiver node responds
* (2)root sends a packet to an internal device, this packet is from external IP network in case the receiver device responds
* this packet, MESH_OPT_RECV_DS_ADDR is required to attach the target DS address.
* @param opt_count option count
* Currently, this API only takes one option, so opt_count is only supported to be 1.
@@ -590,7 +619,7 @@ esp_err_t esp_mesh_stop(void);
* - ESP_ERR_MESH_DISCARD
*/
esp_err_t esp_mesh_send(const mesh_addr_t *to, const mesh_data_t *data,
const int flag, const mesh_opt_t opt[], const int opt_count);
int flag, const mesh_opt_t opt[], int opt_count);
/**
* @brief receive a packet targeted to self over the mesh network
@@ -668,10 +697,10 @@ esp_err_t esp_mesh_recv_toDS(mesh_addr_t *from, mesh_addr_t *to,
* Root conflict function could eliminate redundant roots connected with the same BSSID, but couldn't handle roots
* connected with different BSSID. Because users might have such requirements of setting up routers with same SSID
* for the future replacement. But in that case, if the above situations happen, please make sure applications
* implement forward functions on root to guarantee nodes in different mesh network could communicate with each other.
* implement forward functions on root to guarantee devices in different mesh network can communicate with each other.
* max_connection of mesh softAP is limited by the max number of WiFi softAP supported(max:10).
*
* @attention This API should be called between esp_mesh_init() and esp_mesh_start().
* @attention This API shall be called between esp_mesh_init() and esp_mesh_start().
*
* @param config pointer to mesh stack configuration
*
@@ -696,7 +725,7 @@ esp_err_t esp_mesh_get_config(mesh_cfg_t *config);
/**
* @brief set router configuration
*
* @attention This API should be called between esp_mesh_init() and esp_mesh_start().
* @attention This API shall be called between esp_mesh_init() and esp_mesh_start().
*
* @param router pointer to router configuration
*
@@ -720,7 +749,7 @@ esp_err_t esp_mesh_get_router(mesh_router_t *router);
/**
* @brief set mesh network ID
*
* @attention This API should be called between esp_mesh_init() and esp_mesh_start().
* @attention This API could be called either before esp_mesh_start() or after esp_mesh_start().
*
* @param id pointer to mesh network ID
*
@@ -742,20 +771,20 @@ esp_err_t esp_mesh_set_id(const mesh_addr_t *id);
esp_err_t esp_mesh_get_id(mesh_addr_t *id);
/**
* @brief set node type over the mesh network(Unimplemented)
* @brief set device type over the mesh network(Unimplemented)
*
* @param type node type
* @param type device type
*
* @return
* - ESP_OK
* - ESP_ERR_MESH_NOT_ALLOWED
*/
esp_err_t esp_mesh_set_type(const mesh_type_t type);
esp_err_t esp_mesh_set_type(mesh_type_t type);
/**
* @brief get node type over mesh network
* @brief get device type over mesh network
*
* @attention This API should be called after having received the event MESH_EVENT_PARENT_CONNECTED.
* @attention This API shall be called after having received the event MESH_EVENT_PARENT_CONNECTED.
*
* @return mesh type
*
@@ -765,7 +794,7 @@ mesh_type_t esp_mesh_get_type(void);
/**
* @brief set max layer configuration(max:15, default:15)
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param max_layer max layer value
*
@@ -774,7 +803,7 @@ mesh_type_t esp_mesh_get_type(void);
* - ESP_ERR_MESH_ARGUMENT
* - ESP_ERR_MESH_NOT_ALLOWED
*/
esp_err_t esp_mesh_set_max_layer(const int max_layer);
esp_err_t esp_mesh_set_max_layer(int max_layer);
/**
* @brief get max layer configuration
@@ -786,7 +815,7 @@ int esp_mesh_get_max_layer(void);
/**
* @brief set mesh softAP password
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param pwd pointer to the password
* @param len password length
@@ -796,12 +825,12 @@ int esp_mesh_get_max_layer(void);
* - ESP_ERR_MESH_ARGUMENT
* - ESP_ERR_MESH_NOT_ALLOWED
*/
esp_err_t esp_mesh_set_ap_password(const uint8_t *pwd, const int len);
esp_err_t esp_mesh_set_ap_password(const uint8_t *pwd, int len);
/**
* @brief set mesh softAP authentication mode value
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param authmode authentication mode
*
@@ -810,7 +839,7 @@ esp_err_t esp_mesh_set_ap_password(const uint8_t *pwd, const int len);
* - ESP_ERR_MESH_ARGUMENT
* - ESP_ERR_MESH_NOT_ALLOWED
*/
esp_err_t esp_mesh_set_ap_authmode(const wifi_auth_mode_t authmode);
esp_err_t esp_mesh_set_ap_authmode(wifi_auth_mode_t authmode);
/**
* @brief get mesh softAP authentication mode
@@ -823,7 +852,7 @@ wifi_auth_mode_t esp_mesh_get_ap_authmode(void);
/**
* @brief set mesh softAP max connection value
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param connections the number of max connections
*
@@ -831,7 +860,7 @@ wifi_auth_mode_t esp_mesh_get_ap_authmode(void);
* - ESP_OK
* - ESP_ERR_MESH_ARGUMENT
*/
esp_err_t esp_mesh_set_ap_connections(const int connections);
esp_err_t esp_mesh_set_ap_connections(int connections);
/**
* @brief get mesh softAP max connection configuration
@@ -844,7 +873,7 @@ int esp_mesh_get_ap_connections(void);
/**
* @brief get current layer value over the mesh network
*
* @attention This API should be called after having received the event MESH_EVENT_PARENT_CONNECTED.
* @attention This API shall be called after having received the event MESH_EVENT_PARENT_CONNECTED.
*
* @return layer value
*
@@ -854,7 +883,7 @@ int esp_mesh_get_layer(void);
/**
* @brief get parent BSSID
*
* @attention This API should be called after having received the event MESH_EVENT_PARENT_CONNECTED.
* @attention This API shall be called after having received the event MESH_EVENT_PARENT_CONNECTED.
*
* @param bssid pointer to parent BSSID
*
@@ -865,7 +894,7 @@ int esp_mesh_get_layer(void);
esp_err_t esp_mesh_get_parent_bssid(mesh_addr_t *bssid);
/**
* @brief return if the node is root
* @brief return if the device is root
*
* @return true/false
*
@@ -874,16 +903,20 @@ bool esp_mesh_is_root(void);
/**
* @brief enable/disable mesh networking self-organized, self-organized by default
* if self-organized is disabled, users should set a parent for this node via
* if self-organized is disabled, users should set a parent for this device via
* esp_mesh_set_parent();
*
* @param enable
* @attention This API could be called either before esp_mesh_start() or after esp_mesh_start().
*
* @param enable enable or disable self-organized networking
* @param select_parent if enable self-organized networking, let the device select a new parent or
* keep connecting to the previous parent.
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t esp_mesh_set_self_organized(const bool enable);
esp_err_t esp_mesh_set_self_organized(bool enable, bool select_parent);
/**
* @brief return if mesh networking is self-organized or not
@@ -895,7 +928,7 @@ bool esp_mesh_get_self_organized(void);
/**
* @brief root waive itself
* A node is elected to be a root during the networking mostly because it has a strong RSSI with router.
* A device is elected to be a root during the networking mostly because it has a strong RSSI with router.
* If such superior conditions change, users could call this API to perform a root switch.
*
* In this API, users could specify a desired root address to replace itself or specify an attempts value
@@ -920,14 +953,14 @@ bool esp_mesh_get_self_organized(void);
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t esp_mesh_waive_root(const mesh_vote_t *vote, const int reason);
esp_err_t esp_mesh_waive_root(const mesh_vote_t *vote, int reason);
/**
* @brief set vote percentage threshold for approval of being a root
* During the networking, only obtaining vote percentage reaches this threshold,
* the node could be a root.
* the device could be a root.
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param percentage vote percentage threshold
*
@@ -935,7 +968,7 @@ esp_err_t esp_mesh_waive_root(const mesh_vote_t *vote, const int reason);
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t esp_mesh_set_vote_percentage(const float percentage);
esp_err_t esp_mesh_set_vote_percentage(float percentage);
/**
* @brief get vote percentage threshold for approval of being a root
@@ -955,7 +988,7 @@ float esp_mesh_get_vote_percentage(void);
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t esp_mesh_set_ap_assoc_expire(const int seconds);
esp_err_t esp_mesh_set_ap_assoc_expire(int seconds);
/**
* @brief get mesh softAP associate expired time
@@ -965,27 +998,27 @@ esp_err_t esp_mesh_set_ap_assoc_expire(const int seconds);
int esp_mesh_get_ap_assoc_expire(void);
/**
* @brief get total number of nodes over the mesh network(including root)
* @brief get total number of devices in current network(including root)
*
* @attention The returned value might be incorrect when the network is changing.
**
* @return total number of nodes(including root)
* @return total number of devices(including root)
*/
int esp_mesh_get_total_node_num(void);
/**
* @brief get the number of nodes in routing table(including self)
* @brief get the number of devices in this device's sub-network(including self)
*
* @return the number of nodes in routing table(including self)
* @return the number of devices over this device's sub-network(including self)
*/
int esp_mesh_get_routing_table_size(void);
/**
* @brief get routing table(including itself)
* @brief get routing table of this device's sub-network(including itself)
*
* @param mac pointer to routing table
* @param len routing table size(in bytes)
* @param size pointer to the number of nodes in routing table(including itself)
* @param size pointer to the number of devices in routing table(including itself)
*
* @return
* - ESP_OK
@@ -1004,7 +1037,7 @@ esp_err_t esp_mesh_get_routing_table(mesh_addr_t *mac, int len, int *size);
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t esp_mesh_post_toDS_state(const bool reachable);
esp_err_t esp_mesh_post_toDS_state(bool reachable);
/**
* @brief return the number of packets pending in the queue waiting to be sent by the mesh stack
@@ -1041,9 +1074,9 @@ int esp_mesh_available_txupQ_num(const mesh_addr_t *addr, uint32_t *xseqno_in);
/**
* @brief set queue size
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param qsize default:72(min:36, max:105)
* @param qsize default:32(min:16)
*
* @return
* - ESP_OK
@@ -1068,7 +1101,7 @@ int esp_mesh_get_xon_qsize(void);
* - ESP_WIFI_ERR_NOT_INIT
* - ESP_WIFI_ERR_NOT_START
*/
esp_err_t esp_mesh_allow_root_conflicts(const bool allowed);
esp_err_t esp_mesh_allow_root_conflicts(bool allowed);
/**
* @brief check if allow more than one root to exist in one network
@@ -1080,26 +1113,26 @@ bool esp_mesh_is_root_conflicts_allowed(void);
/**
* @brief set group ID addresses
*
* @param addr pointer to new addresses
* @param num number of addresses
* @param addr pointer to new group ID addresses
* @param num the number of group ID addresses
*
* @return
* - ESP_OK
* - ESP_MESH_ERR_ARGUMENT
*/
esp_err_t esp_mesh_set_group_id(const mesh_addr_t *addr, const int num);
esp_err_t esp_mesh_set_group_id(const mesh_addr_t *addr, int num);
/**
* @brief delete group ID addresses
*
* @param addr pointer to deleted address
* @param num number of addresses
* @param addr pointer to deleted group ID address
* @param num the number of group ID addresses
*
* @return
* - ESP_OK
* - ESP_MESH_ERR_ARGUMENT
*/
esp_err_t esp_mesh_delete_group_id(const mesh_addr_t *addr, const int num);
esp_err_t esp_mesh_delete_group_id(const mesh_addr_t *addr, int num);
/**
* @brief get the number of group ID addresses
@@ -1111,14 +1144,14 @@ int esp_mesh_get_group_num(void);
/**
* @brief get group ID addresses
*
* @param addr pointer to group address
* @param num number of addresses
* @param addr pointer to group ID addresses
* @param num the number of group ID addresses
*
* @return
* - ESP_OK
* - ESP_MESH_ERR_ARGUMENT
*/
esp_err_t esp_mesh_get_group_list(mesh_addr_t *addr, const int num);
esp_err_t esp_mesh_get_group_list(mesh_addr_t *addr, int num);
/**
* @brief check if the specified group address is my group
@@ -1130,7 +1163,7 @@ bool esp_mesh_is_my_group(const mesh_addr_t *addr);
/**
* @brief set mesh network capacity
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called before esp_mesh_start().
*
* @param num mesh network capacity
*
@@ -1161,29 +1194,30 @@ esp_err_t esp_mesh_set_ie_crypto_funcs(const mesh_crypto_funcs_t *crypto_funcs);
/**
* @brief set mesh ie crypto key
*
* @attention This API should be called before esp_mesh_start().
* @attention This API shall be called after esp_mesh_set_config() and before esp_mesh_start().
*
* @param key crypto key
* @param len the present implementation only supports 32
* @param key ASCII crypto key
* @param len length in bytes, range:8~64
*
* @return
* - ESP_OK
* - ESP_ERR_MESH_NOT_ALLOWED
* - ESP_ERR_MESH_NOT_CONFIG
* - ESP_MESH_ERR_ARGUMENT
*/
esp_err_t esp_mesh_set_ie_crypto_key(const uint8_t *key, int len);
esp_err_t esp_mesh_set_ie_crypto_key(const char *key, int len);
/**
* @brief get mesh ie crypto key
*
* @param key crypto key
* @param len the present implementation only supports 32
* @param key ASCII crypto key
* @param len length in bytes, range:8~64
*
* @return
* - ESP_OK
* - ESP_MESH_ERR_ARGUMENT
*/
esp_err_t esp_mesh_get_ie_crypto_key(uint8_t *key, int len);
esp_err_t esp_mesh_get_ie_crypto_key(char *key, int len);
/**
* @brief set delay time before starting root healing
@@ -1213,21 +1247,21 @@ int esp_mesh_get_root_healing_delay(void);
esp_err_t esp_mesh_set_event_cb(const mesh_event_cb_t event_cb);
/**
* @brief set Root Fixed setting for nodes
* If Root Fixed setting of nodes is enabled, they won't compete to be a root.
* If a scenario needs a fixed root, all nodes in this network must enable this setting.
* @brief set Fixed Root setting for the device
* If Fixed Root setting of the device is enabled, it won't compete to be a root.
* If a scenario needs a fixed root, all devices in this network shall enable this setting.
*
* @param enable enable or not
*
* @return
* - ESP_OK
*/
esp_err_t esp_mesh_fix_root(const bool enable);
esp_err_t esp_mesh_fix_root(bool enable);
/**
* @brief check if Root Fixed setting is enabled
* Root Fixed setting can be changed by API esp_mesh_fix_root().
* Root Fixed setting can also be changed by event MESH_EVENT_ROOT_FIXED.
* @brief check if Fixed Root setting is enabled
* Fixed Root setting can be changed by API esp_mesh_fix_root().
* Fixed Root setting can also be changed by event MESH_EVENT_ROOT_FIXED.
*
* @return true/false
*/
@@ -1235,9 +1269,9 @@ bool esp_mesh_is_root_fixed(void);
/**
* @brief set a specified parent
* self-organized networking will be disabled.
*
* @param parent parent configuration
* @param parent parent configuration, the ssid and the channel of the parent are mandatory.
* @param parent_mesh_id parent mesh ID, if not set, use the device default one.
* @param my_type my mesh type
* @param my_layer my mesh layer
*
@@ -1246,8 +1280,35 @@ bool esp_mesh_is_root_fixed(void);
* - ESP_ERR_ARGUMENT
* - ESP_ERR_MESH_NOT_CONFIG
*/
esp_err_t esp_mesh_set_parent(wifi_config_t *parent, mesh_type_t my_type, int my_layer);
esp_err_t esp_mesh_set_parent(const wifi_config_t *parent, const mesh_addr_t *parent_mesh_id, mesh_type_t my_type, int my_layer);
/**
* @brief get mesh networking IE length of one AP
*
* @param len mesh networking IE length
*
* @return
* - ESP_OK
* - ESP_ERR_WIFI_NOT_INIT
* - ESP_ERR_WIFI_ARG
* - ESP_ERR_WIFI_FAIL
*/
esp_err_t esp_mesh_scan_get_ap_ie_len(int *len);
/**
* @brief get AP record
* Different from esp_wifi_scan_get_ap_records(), this API only gets one of scanned APs each time.
*
* @param ap_record pointer to the AP record
* @param buffer pointer to the mesh networking IE of this AP
*
* @return
* - ESP_OK
* - ESP_ERR_WIFI_NOT_INIT
* - ESP_ERR_WIFI_ARG
* - ESP_ERR_WIFI_FAIL
*/
esp_err_t esp_mesh_scan_get_ap_record(wifi_ap_record_t *ap_record, void *buffer);
#ifdef __cplusplus
}

View File

@@ -49,6 +49,46 @@ typedef struct {
int backoff_rssi; /* RSSI threshold for connecting to the root */
} mesh_switch_parent_t;
/**
* @brief mesh networking IE
*/
typedef struct {
/**< mesh networking IE head */
uint8_t eid; /**< element ID */
uint8_t len; /**< element length */
uint8_t oui[3]; /**< organization identifier */
/**< mesh networking IE content */
uint8_t type; /** mesh networking IE type */
uint8_t encryped : 1; /**< if mesh networking IE is encrypted */
uint8_t version : 7; /**< mesh networking IE version */
/**< content */
uint8_t mesh_type; /**< mesh device type */
uint8_t mesh_id[6]; /**< mesh ID */
uint8_t layer_cap; /**< max layer */
uint8_t layer; /**< current layer */
uint8_t assoc_cap; /**< max connections of mesh AP */
uint8_t assoc; /**< current connections */
uint8_t leaf_cap; /**< leaf capacity */
uint8_t leaf_assoc; /**< the number of current connected leaf */
uint16_t root_cap; /**< root capacity */
uint16_t self_cap; /**< self capacity */
uint16_t layer2_cap; /**< layer2 capacity */
uint16_t scan_ap_num; /**< the number of scanned APs */
int8_t rssi; /**< rssi of the parent */
int8_t router_rssi; /**< rssi of the router */
uint8_t flag; /**< flag of networking */
uint8_t rc_addr[6]; /**< root address */
int8_t rc_rssi; /**< root rssi */
uint8_t vote_addr[6]; /**< voter address */
int8_t vote_rssi; /**< vote rssi of the router */
uint8_t vote_ttl; /**< vote ttl */
uint16_t votes; /**< votes */
uint16_t my_votes; /**< my votes */
uint8_t reason; /**< reason */
uint8_t child[6]; /**< child address */
uint8_t toDS; /**< toDS state */
} __attribute__((packed)) mesh_assoc_t;
/*******************************************************
* Function Definitions
*******************************************************/

View File

@@ -37,7 +37,9 @@ typedef struct {
* @brief Opaque PHY calibration data
*/
typedef struct {
uint8_t opaque[1904]; /*!< calibration data */
uint8_t version[4]; /*!< PHY version */
uint8_t mac[6]; /*!< The MAC address of the station */
uint8_t opaque[1894]; /*!< calibration data */
} esp_phy_calibration_data_t;
typedef enum {

View File

@@ -38,6 +38,7 @@ typedef enum {
ESP_PD_DOMAIN_RTC_PERIPH, //!< RTC IO, sensors and ULP co-processor
ESP_PD_DOMAIN_RTC_SLOW_MEM, //!< RTC slow memory
ESP_PD_DOMAIN_RTC_FAST_MEM, //!< RTC fast memory
ESP_PD_DOMAIN_XTAL, //!< XTAL oscillator
ESP_PD_DOMAIN_MAX //!< Number of domains
} esp_sleep_pd_domain_t;

View File

@@ -189,6 +189,13 @@ esp_err_t esp_timer_delete(esp_timer_handle_t timer);
*/
int64_t esp_timer_get_time();
/**
* @brief Get the timestamp when the next timeout is expected to occur
* @return Timestamp of the nearest timer event, in microseconds.
* The timebase is the same as for the values returned by esp_timer_get_time.
*/
int64_t esp_timer_get_next_alarm();
/**
* @brief Dump the list of timers to a stream
*

0
components/esp32/include/esp_types.h Executable file → Normal file
View File

176
components/esp32/include/esp_wifi.h Executable file → Normal file
View File

@@ -67,6 +67,7 @@
#include "esp_wifi_types.h"
#include "esp_wifi_crypto_types.h"
#include "esp_event.h"
#include "esp_wifi_os_adapter.h"
#ifdef __cplusplus
extern "C" {
@@ -93,18 +94,21 @@ extern "C" {
*/
typedef struct {
system_event_handler_t event_handler; /**< WiFi event handler */
wifi_osi_funcs_t* osi_funcs; /**< WiFi OS functions */
wpa_crypto_funcs_t wpa_crypto_funcs; /**< WiFi station crypto functions when connect */
int static_rx_buf_num; /**< WiFi static RX buffer number */
int dynamic_rx_buf_num; /**< WiFi dynamic RX buffer number */
int tx_buf_type; /**< WiFi TX buffer type */
int static_tx_buf_num; /**< WiFi static TX buffer number */
int dynamic_tx_buf_num; /**< WiFi dynamic TX buffer number */
int csi_enable; /**< WiFi channel state information enable flag */
int ampdu_rx_enable; /**< WiFi AMPDU RX feature enable flag */
int ampdu_tx_enable; /**< WiFi AMPDU TX feature enable flag */
int nvs_enable; /**< WiFi NVS flash enable flag */
int nano_enable; /**< Nano option for printf/scan family enable flag */
int tx_ba_win; /**< WiFi Block Ack TX window size */
int rx_ba_win; /**< WiFi Block Ack RX window size */
int wifi_task_core_id; /**< WiFi Task Core ID */
int magic; /**< WiFi init magic number, it should be the last field */
} wifi_init_config_t;
@@ -120,6 +124,12 @@ typedef struct {
#define WIFI_DYNAMIC_TX_BUFFER_NUM 0
#endif
#if CONFIG_ESP32_WIFI_CSI_ENABLED
#define WIFI_CSI_ENABLED 1
#else
#define WIFI_CSI_ENABLED 0
#endif
#if CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED
#define WIFI_AMPDU_RX_ENABLED 1
#else
@@ -160,20 +170,29 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
#define WIFI_DEFAULT_RX_BA_WIN 0 /* unused if ampdu_rx_enable == false */
#endif
#if CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1
#define WIFI_TASK_CORE_ID 1
#else
#define WIFI_TASK_CORE_ID 0
#endif
#define WIFI_INIT_CONFIG_DEFAULT() { \
.event_handler = &esp_event_send, \
.osi_funcs = &g_wifi_osi_funcs, \
.wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
.static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\
.dynamic_rx_buf_num = CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM,\
.tx_buf_type = CONFIG_ESP32_WIFI_TX_BUFFER_TYPE,\
.static_tx_buf_num = WIFI_STATIC_TX_BUFFER_NUM,\
.dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\
.csi_enable = WIFI_CSI_ENABLED,\
.ampdu_rx_enable = WIFI_AMPDU_RX_ENABLED,\
.ampdu_tx_enable = WIFI_AMPDU_TX_ENABLED,\
.nvs_enable = WIFI_NVS_ENABLED,\
.nano_enable = WIFI_NANO_FORMAT_ENABLED,\
.tx_ba_win = WIFI_DEFAULT_TX_BA_WIN,\
.rx_ba_win = WIFI_DEFAULT_RX_BA_WIN,\
.wifi_task_core_id = WIFI_TASK_CORE_ID,\
.magic = WIFI_INIT_CONFIG_MAGIC\
};
@@ -674,6 +693,31 @@ esp_err_t esp_wifi_set_promiscuous_filter(const wifi_promiscuous_filter_t *filte
*/
esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter);
/**
* @brief Enable subtype filter of the control packet in promiscuous mode.
*
* @note The default filter is to filter none control packet.
*
* @param filter the subtype of the control packet filtered in promiscuous mode.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
*/
esp_err_t esp_wifi_set_promiscuous_ctrl_filter(const wifi_promiscuous_filter_t *filter);
/**
* @brief Get the subtype filter of the control packet in promiscuous mode.
*
* @param[out] filter store the current status of subtype filter of the control packet in promiscuous mode
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument
*/
esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter);
/**
* @brief Set the configuration of the ESP32 STA or AP
*
@@ -757,7 +801,7 @@ esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
* - ESP_ERR_WIFI_MODE: WiFi internal error, the station/soft-AP control block is invalid
* - others: refer to error code in esp_err.h
*/
esp_err_t esp_wifi_set_auto_connect(bool en);
esp_err_t esp_wifi_set_auto_connect(bool en) __attribute__ ((deprecated));
/**
* @brief Get the auto connect flag
@@ -769,7 +813,7 @@ esp_err_t esp_wifi_set_auto_connect(bool en);
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_INVALID_ARG: invalid argument
*/
esp_err_t esp_wifi_get_auto_connect(bool *en);
esp_err_t esp_wifi_get_auto_connect(bool *en) __attribute__ ((deprecated));
/**
* @brief Set 802.11 Vendor-Specific Information Element
@@ -904,6 +948,134 @@ esp_err_t esp_wifi_set_event_mask(uint32_t mask);
*/
esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
/**
* @brief Send raw ieee80211 data
*
* @attention Currently only support for sending beacon/probe request/probe response/action and non-QoS
* data frame
*
* @param ifx interface if the Wi-Fi mode is Station, the ifx should be WIFI_IF_STA. If the Wi-Fi
* mode is SoftAP, the ifx should be WIFI_IF_AP. If the Wi-Fi mode is Station+SoftAP, the
* ifx should be WIFI_IF_STA or WIFI_IF_AP. If the ifx is wrong, the API returns ESP_ERR_WIFI_IF.
* @param buffer raw ieee80211 buffer
* @param len the length of raw buffer, the len must be <= 1500 Bytes and >= 24 Bytes
* @param en_sys_seq indicate whether use the internal sequence number. If en_sys_seq is false, the
* sequence in raw buffer is unchanged, otherwise it will be overwritten by WiFi driver with
* the system sequence number.
* Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both
* en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi
* connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_WIFI_ARG is returned.
*
* @return
* - ESP_OK: success
* - ESP_ERR_WIFI_IF: Invalid interface
* - ESP_ERR_INVALID_ARG: Invalid parameter
* - ESP_ERR_WIFI_NO_MEM: out of memory
*/
esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
/**
* @brief The RX callback function of Channel State Information(CSI) data.
*
* Each time a CSI data is received, the callback function will be called.
*
* @param ctx context argument, passed to esp_wifi_set_csi_rx_cb() when registering callback function.
* @param data CSI data received.
*
*/
typedef void (* wifi_csi_cb_t)(void *ctx, wifi_csi_info_t *data);
/**
* @brief Register the RX callback function of CSI data.
*
* Each time a CSI data is received, the callback function will be called.
*
* @param cb callback
* @param ctx context argument, passed to callback function
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
*/
esp_err_t esp_wifi_set_csi_rx_cb(wifi_csi_cb_t cb, void *ctx);
/**
* @brief Set CSI data configuration
*
* @param config configuration
*
* return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
* - ESP_ERR_INVALID_ARG: invalid argument
*/
esp_err_t esp_wifi_set_csi_config(const wifi_csi_config_t *config);
/**
* @brief Enable or disable CSI
*
* @param en true - enable, false - disable
*
* return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
* - ESP_ERR_INVALID_ARG: invalid argument
*/
esp_err_t esp_wifi_set_csi(bool en);
/**
* @brief Set antenna GPIO configuration
*
* @param config Antenna GPIO configuration.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid GPIO number etc
*/
esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config);
/**
* @brief Get current antenna GPIO configuration
*
* @param config Antenna GPIO configuration.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL
*/
esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config);
/**
* @brief Set antenna configuration
*
* @param config Antenna configuration.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid antenna mode or invalid GPIO number
*/
esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config);
/**
* @brief Get current antenna configuration
*
* @param config Antenna configuration.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL
*/
esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config);
#ifdef __cplusplus
}

View File

@@ -80,7 +80,7 @@ typedef esp_crypto_hash_t * (*esp_crypto_hash_init_t)(esp_crypto_hash_alg_t alg,
* @param len Length of the buffer.
*
*/
typedef void * (*esp_crypto_hash_update_t)(esp_crypto_hash_t *ctx, const unsigned char *data, int len);
typedef void (*esp_crypto_hash_update_t)(esp_crypto_hash_t *ctx, const unsigned char *data, int len);
/**
* @brief The crypto callback function used in wpa enterprise hash operation when connect.
@@ -95,7 +95,7 @@ typedef void * (*esp_crypto_hash_update_t)(esp_crypto_hash_t *ctx, const unsigne
* or -2 on other failures (including failed crypto_hash_update() operations)
*
*/
typedef int * (*esp_crypto_hash_finish_t)(esp_crypto_hash_t *ctx, unsigned char *hash, int *len);
typedef int (*esp_crypto_hash_finish_t)(esp_crypto_hash_t *ctx, unsigned char *hash, int *len);
/**
* @brief The AES callback function when do WPS connect.
@@ -105,7 +105,7 @@ typedef int * (*esp_crypto_hash_finish_t)(esp_crypto_hash_t *ctx, unsigned char
* @param data Data to encrypt in-place.
* @param data_len Length of data in bytes (must be divisible by 16)
*/
typedef int * (*esp_aes_128_encrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
typedef int (*esp_aes_128_encrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
/**
* @brief The AES callback function when do WPS connect.
@@ -116,7 +116,7 @@ typedef int * (*esp_aes_128_encrypt_t)(const unsigned char *key, const unsigned
* @param data_len Length of data in bytes (must be divisible by 16)
*
*/
typedef int * (*esp_aes_128_decrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
typedef int (*esp_aes_128_decrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
/**
* @brief The AES callback function when do STA connect.
@@ -127,7 +127,7 @@ typedef int * (*esp_aes_128_decrypt_t)(const unsigned char *key, const unsigned
* @param cipher Wrapped key, (n + 1) * 64 bits
*
*/
typedef int * (*esp_aes_wrap_t)(const unsigned char *kek, int n, const unsigned char *plain, unsigned char *cipher);
typedef int (*esp_aes_wrap_t)(const unsigned char *kek, int n, const unsigned char *plain, unsigned char *cipher);
/**
* @brief The AES callback function when do STA connect.
@@ -138,7 +138,7 @@ typedef int * (*esp_aes_wrap_t)(const unsigned char *kek, int n, const unsigned
* @param plain Plaintext key, n * 64 bits
*
*/
typedef int * (*esp_aes_unwrap_t)(const unsigned char *kek, int n, const unsigned char *cipher, unsigned char *plain);
typedef int (*esp_aes_unwrap_t)(const unsigned char *kek, int n, const unsigned char *cipher, unsigned char *plain);
/**
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
@@ -162,7 +162,7 @@ typedef esp_crypto_cipher_t * (*esp_crypto_cipher_init_t)(esp_crypto_cipher_alg_
* @param len Length of the plaintext.
*
*/
typedef int * (*esp_crypto_cipher_encrypt_t)(esp_crypto_cipher_t *ctx,
typedef int (*esp_crypto_cipher_encrypt_t)(esp_crypto_cipher_t *ctx,
const unsigned char *plain, unsigned char *crypt, int len);
/**
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
@@ -174,7 +174,7 @@ typedef int * (*esp_crypto_cipher_encrypt_t)(esp_crypto_cipher_t *ctx,
* @param len Length of the cipher text.
*
*/
typedef int * (*esp_crypto_cipher_decrypt_t)(esp_crypto_cipher_t *ctx,
typedef int (*esp_crypto_cipher_decrypt_t)(esp_crypto_cipher_t *ctx,
const unsigned char *crypt, unsigned char *plain, int len);
/**
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
@@ -183,7 +183,7 @@ typedef int * (*esp_crypto_cipher_decrypt_t)(esp_crypto_cipher_t *ctx,
* @param ctx Context pointer from esp_crypto_cipher_init_t callback function.
*
*/
typedef void * (*esp_crypto_cipher_deinit_t)(esp_crypto_cipher_t *ctx);
typedef void (*esp_crypto_cipher_deinit_t)(esp_crypto_cipher_t *ctx);
/**
* @brief The SHA256 callback function when do WPS connect.
@@ -195,7 +195,7 @@ typedef void * (*esp_crypto_cipher_deinit_t)(esp_crypto_cipher_t *ctx);
* @param mac Buffer for the hash (20 bytes).
*
*/
typedef void * (*esp_hmac_sha256_t)(const unsigned char *key, int key_len, const unsigned char *data,
typedef void (*esp_hmac_sha256_t)(const unsigned char *key, int key_len, const unsigned char *data,
int data_len, unsigned char *mac);
/**
@@ -209,7 +209,7 @@ typedef void * (*esp_hmac_sha256_t)(const unsigned char *key, int key_len, const
* @param mac Buffer for the hash (32 bytes).
*
*/
typedef void * (*esp_hmac_sha256_vector_t)(const unsigned char *key, int key_len, int num_elem,
typedef void (*esp_hmac_sha256_vector_t)(const unsigned char *key, int key_len, int num_elem,
const unsigned char *addr[], const int *len, unsigned char *mac);
/**
@@ -224,7 +224,7 @@ typedef void * (*esp_hmac_sha256_vector_t)(const unsigned char *key, int key_len
* @param buf_len Number of bytes of key to generate.
*
*/
typedef void * (*esp_sha256_prf_t)(const unsigned char *key, int key_len, const char *label,
typedef void (*esp_sha256_prf_t)(const unsigned char *key, int key_len, const char *label,
const unsigned char *data, int data_len, unsigned char *buf, int buf_len);
/**
@@ -233,10 +233,10 @@ typedef void * (*esp_sha256_prf_t)(const unsigned char *key, int key_len, const
* @param num_elem Number of elements in the data vector.
* @param addr Pointers to the data areas.
* @param len Lengths of the data blocks.
* @param mac Buffer for the hash.
* @paramac Buffer for the hash.
*
*/
typedef int * (*esp_sha256_vector_t)(int num_elem, const unsigned char *addr[], const int *len,
typedef int (*esp_sha256_vector_t)(int num_elem, const unsigned char *addr[], const int *len,
unsigned char *mac);
/**
@@ -253,10 +253,444 @@ typedef int * (*esp_sha256_vector_t)(int num_elem, const unsigned char *addr[],
* @param result_len Result length (max buffer size on input, real len on output).
*
*/
typedef int * (*esp_crypto_mod_exp_t)(const unsigned char *base, int base_len,
typedef int (*esp_crypto_mod_exp_t)(const unsigned char *base, int base_len,
const unsigned char *power, int power_len,
const unsigned char *modulus, int modulus_len,
unsigned char *result, unsigned int *result_len);
/**
* @brief HMAC-MD5 over data buffer (RFC 2104)'
*
* @key: Key for HMAC operations
* @key_len: Length of the key in bytes
* @data: Pointers to the data area
* @data_len: Length of the data area
* @mac: Buffer for the hash (16 bytes)
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_hmac_md5_t)(const unsigned char *key, unsigned int key_len, const unsigned char *data,
unsigned int data_len, unsigned char *mac);
/**
* @brief HMAC-MD5 over data vector (RFC 2104)
*
* @key: Key for HMAC operations
* @key_len: Length of the key in bytes
* @num_elem: Number of elements in the data vector
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash (16 bytes)
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_hmac_md5_vector_t)(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
const unsigned char *addr[], const unsigned int *len, unsigned char *mac);
/**
* @brief HMAC-SHA1 over data buffer (RFC 2104)
*
* @key: Key for HMAC operations
* @key_len: Length of the key in bytes
* @data: Pointers to the data area
* @data_len: Length of the data area
* @mac: Buffer for the hash (20 bytes)
* Returns: 0 on success, -1 of failure
*/
typedef int (*esp_hmac_sha1_t)(const unsigned char *key, unsigned int key_len, const unsigned char *data,
unsigned int data_len, unsigned char *mac);
/**
* @brief HMAC-SHA1 over data vector (RFC 2104)
*
* @key: Key for HMAC operations
* @key_len: Length of the key in bytes
* @num_elem: Number of elements in the data vector
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash (20 bytes)
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_hmac_sha1_vector_t)(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
const unsigned char *addr[], const unsigned int *len, unsigned char *mac);
/**
* @brief SHA1-based Pseudo-Random Function (PRF) (IEEE 802.11i, 8.5.1.1)
*
* @key: Key for PRF
* @key_len: Length of the key in bytes
* @label: A unique label for each purpose of the PRF
* @data: Extra data to bind into the key
* @data_len: Length of the data
* @buf: Buffer for the generated pseudo-random key
* @buf_len: Number of bytes of key to generate
* Returns: 0 on success, -1 of failure
*
* This function is used to derive new, cryptographically separate keys from a
* given key (e.g., PMK in IEEE 802.11i).
*/
typedef int (*esp_sha1_prf_t)(const unsigned char *key, unsigned int key_len, const char *label,
const unsigned char *data, unsigned int data_len, unsigned char *buf, unsigned int buf_len);
/**
* @brief SHA-1 hash for data vector
*
* @num_elem: Number of elements in the data vector
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_sha1_vector_t)(unsigned int num_elem, const unsigned char *addr[], const unsigned int *len,
unsigned char *mac);
/**
* @brief SHA1-based key derivation function (PBKDF2) for IEEE 802.11i
*
* @passphrase: ASCII passphrase
* @ssid: SSID
* @ssid_len: SSID length in bytes
* @iterations: Number of iterations to run
* @buf: Buffer for the generated key
* @buflen: Length of the buffer in bytes
* Returns: 0 on success, -1 of failure
*
* This function is used to derive PSK for WPA-PSK. For this protocol,
* iterations is set to 4096 and buflen to 32. This function is described in
* IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0.
*/
typedef int (*esp_pbkdf2_sha1_t)(const char *passphrase, const char *ssid, unsigned int ssid_len,
int iterations, unsigned char *buf, unsigned int buflen);
/**
* @brief XOR RC4 stream to given data with skip-stream-start
*
* @key: RC4 key
* @keylen: RC4 key length
* @skip: number of bytes to skip from the beginning of the RC4 stream
* @data: data to be XOR'ed with RC4 stream
* @data_len: buf length
* Returns: 0 on success, -1 on failure
*
* Generate RC4 pseudo random stream for the given key, skip beginning of the
* stream, and XOR the end result with the data buffer to perform RC4
* encryption/decryption.
*/
typedef int (*esp_rc4_skip_t)(const unsigned char *key, unsigned int keylen, unsigned int skip,
unsigned char *data, unsigned int data_len);
/**
* @brief MD5 hash for data vector
*
* @num_elem: Number of elements in the data vector
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_md5_vector_t)(unsigned int num_elem, const unsigned char *addr[], const unsigned int *len,
unsigned char *mac);
/**
* @brief Encrypt one AES block
*
* @ctx: Context pointer from aes_encrypt_init()
* @plain: Plaintext data to be encrypted (16 bytes)
* @crypt: Buffer for the encrypted data (16 bytes)
*/
typedef void (*esp_aes_encrypt_t)(void *ctx, const unsigned char *plain, unsigned char *crypt);
/**
* @brief Initialize AES for encryption
*
* @key: Encryption key
* @len: Key length in bytes (usually 16, i.e., 128 bits)
* Returns: Pointer to context data or %NULL on failure
*/
typedef void * (*esp_aes_encrypt_init_t)(const unsigned char *key, unsigned int len);
/**
* @brief Deinitialize AES encryption
*
* @ctx: Context pointer from aes_encrypt_init()
*/
typedef void (*esp_aes_encrypt_deinit_t)(void *ctx);
/**
* @brief Decrypt one AES block
*
* @ctx: Context pointer from aes_encrypt_init()
* @crypt: Encrypted data (16 bytes)
* @plain: Buffer for the decrypted data (16 bytes)
*/
typedef void (*esp_aes_decrypt_t)(void *ctx, const unsigned char *crypt, unsigned char *plain);
/**
* @brief Initialize AES for decryption
*
* @key: Decryption key
* @len: Key length in bytes (usually 16, i.e., 128 bits)
* Returns: Pointer to context data or %NULL on failure
*/
typedef void * (*esp_aes_decrypt_init_t)(const unsigned char *key, unsigned int len);
/**
* @brief Deinitialize AES decryption
*
* @ctx: Context pointer from aes_encrypt_init()
*/
typedef void (*esp_aes_decrypt_deinit_t)(void *ctx);
/**
* @brief Initialize TLS library
*
* @conf: Configuration data for TLS library
* Returns: Context data to be used as tls_ctx in calls to other functions,
* or %NULL on failure.
*
* Called once during program startup and once for each RSN pre-authentication
* session. In other words, there can be two concurrent TLS contexts. If global
* library initialization is needed (i.e., one that is shared between both
* authentication types), the TLS library wrapper should maintain a reference
* counter and do global initialization only when moving from 0 to 1 reference.
*/
typedef void * (*esp_tls_init_t)(void);
/**
* @brief Deinitialize TLS library
*
* @tls_ctx: TLS context data from tls_init()
*
* Called once during program shutdown and once for each RSN pre-authentication
* session. If global library deinitialization is needed (i.e., one that is
* shared between both authentication types), the TLS library wrapper should
* maintain a reference counter and do global deinitialization only when moving
* from 1 to 0 references.
*/
typedef void (*esp_tls_deinit_t)(void *tls_ctx);
/**
* @brief Add certificate and private key for connect
* @sm: eap state machine
*
* Returns: 0 for success, -1 state machine didn't exist, -2 short of certificate or key
*/
typedef int (*esp_eap_peer_blob_init_t)(void *sm);
/**
* @brief delete the certificate and private
*
* @sm: eap state machine
*
*/
typedef void (*esp_eap_peer_blob_deinit_t)(void *sm);
/**
* @brief Initialize the eap state machine
*
* @sm: eap state machine
* @private_key_passwd: the start address of private_key_passwd
* @private_key_passwd_len: length of private_key_password
*
* Returns: 0 is success, -1 state machine didn't exist, -2 short of parameters
*
*/
typedef int (*esp_eap_peer_config_init_t)(void *sm, unsigned char *private_key_passwd,int private_key_passwd_len);
/**
* @brief Deinit the eap state machine
*
* @sm: eap state machine
*
*/
typedef void (*esp_eap_peer_config_deinit_t)(void *sm);
/**
* @brief Register the eap method
*
* Note: ESP32 only support PEAP/TTLS/TLS three eap methods now.
*
*/
typedef int (*esp_eap_peer_register_methods_t)(void);
/**
* @brief remove the eap method
*
* Note: ESP32 only support PEAP/TTLS/TLS three eap methods now.
*
*/
typedef void (*esp_eap_peer_unregister_methods_t)(void);
/**
* @brief remove the eap method before build new connect
*
* @sm: eap state machine
* @txt: not used now
*/
typedef void (*esp_eap_deinit_prev_method_t)(void *sm, const char *txt);
/**
* @brief Get EAP method based on type number
*
* @vendor: EAP Vendor-Id (0 = IETF)
* @method: EAP type number
* Returns: Pointer to EAP method or %NULL if not found
*/
typedef const void * (*esp_eap_peer_get_eap_method_t)(int vendor, int method);
/**
* @brief Abort EAP authentication
*
* @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
*
* Release system resources that have been allocated for the authentication
* session without fully deinitializing the EAP state machine.
*/
typedef void (*esp_eap_sm_abort_t)(void *sm);
/**
* @brief Build EAP-NAK for the current network
*
* @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
* @type: EAP type of the fail reason
* @id: EAP identifier for the packet
*
* This function allocates and builds a nak packet for the
* current network. The caller is responsible for freeing the returned data.
*/
typedef void * (*esp_eap_sm_build_nak_t)(void *sm, int type, unsigned char id);
/**
* @brief Build EAP-Identity/Response for the current network
*
* @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
* @id: EAP identifier for the packet
* @encrypted: Whether the packet is for encrypted tunnel (EAP phase 2)
* Returns: Pointer to the allocated EAP-Identity/Response packet or %NULL on
* failure
*
* This function allocates and builds an EAP-Identity/Response packet for the
* current network. The caller is responsible for freeing the returned data.
*/
typedef void * (*esp_eap_sm_build_identity_resp_t)(void *sm, unsigned char id, int encrypted);
/**
* @brief Allocate a buffer for an EAP message
*
* @vendor: Vendor-Id (0 = IETF)
* @type: EAP type
* @payload_len: Payload length in bytes (data after Type)
* @code: Message Code (EAP_CODE_*)
* @identifier: Identifier
* Returns: Pointer to the allocated message buffer or %NULL on error
*
* This function can be used to allocate a buffer for an EAP message and fill
* in the EAP header. This function is automatically using expanded EAP header
* if the selected Vendor-Id is not IETF. In other words, most EAP methods do
* not need to separately select which header type to use when using this
* function to allocate the message buffers. The returned buffer has room for
* payload_len bytes and has the EAP header and Type field already filled in.
*/
typedef void * (*esp_eap_msg_alloc_t)(int vendor, int type, unsigned int payload_len,
unsigned char code, unsigned char identifier);
/**
* @brief get the enrollee mac address
* @mac_addr: instore the mac address of enrollee
* @uuid: Universally Unique Identifer of the enrollee
*
*/
typedef void (*esp_uuid_gen_mac_addr_t)(const unsigned char *mac_addr, unsigned char *uuid);
/**
* @brief free the message after finish DH
*
*/
typedef void * (*esp_dh5_free_t)(void *ctx);
/**
* @brief Build WPS IE for (Re)Association Request
*
* @req_type: Value for Request Type attribute
* Returns: WPS IE or %NULL on failure
*
* The caller is responsible for freeing the buffer.
*/
typedef void * (*esp_wps_build_assoc_req_ie_t)(int req_type);
/**
* @brief Build WPS IE for (Re)Association Response
*
* Returns: WPS IE or %NULL on failure
*
* The caller is responsible for freeing the buffer.
*/
typedef void * (*esp_wps_build_assoc_resp_ie_t)(void);
/**
* @brief Build WPS IE for Probe Request
*
* @pw_id: Password ID (DEV_PW_PUSHBUTTON for active PBC and DEV_PW_DEFAULT for
* most other use cases)
* @dev: Device attributes
* @uuid: Own UUID
* @req_type: Value for Request Type attribute
* @num_req_dev_types: Number of requested device types
* @req_dev_types: Requested device types (8 * num_req_dev_types octets) or
* %NULL if none
* Returns: WPS IE or %NULL on failure
*
* The caller is responsible for freeing the buffer.
*/
typedef void * (*esp_wps_build_probe_req_ie_t)(uint16_t pw_id, void *dev, const unsigned char *uuid,
int req_type, unsigned int num_req_dev_types, const unsigned char *req_dev_types);
/**
* @brief build public key for exchange in M1
*
*
*/
typedef int (*esp_wps_build_public_key_t)(void *wps, void *msg, int mode);
/**
* @brief get the wps information in exchange password
*
*
*/
typedef void * (*esp_wps_enrollee_get_msg_t)(void *wps, void *op_code);
/**
* @brief deal with the wps information in exchange password
*
*
*/
typedef int (*esp_wps_enrollee_process_msg_t)(void *wps, int op_code, const void *msg);
/**
* @brief Generate a random PIN
*
* Returns: Eight digit PIN (i.e., including the checksum digit)
*/
typedef unsigned int (*esp_wps_generate_pin_t)(void);
/**
* @brief Check whether WPS IE indicates active PIN
*
* @msg: WPS IE contents from Beacon or Probe Response frame
* Returns: 1 if PIN Registrar is active, 0 if not
*/
typedef int (*esp_wps_is_selected_pin_registrar_t)(const void *msg, unsigned char *bssid);
/**
* @brief Check whether WPS IE indicates active PBC
*
* @msg: WPS IE contents from Beacon or Probe Response frame
* Returns: 1 if PBC Registrar is active, 0 if not
*/
typedef int (*esp_wps_is_selected_pbc_registrar_t)(const void *msg, unsigned char *bssid);
/**
* @brief The crypto callback function structure used when do station security connect.
* The structure can be set as software crypto or the crypto optimized by ESP32
@@ -267,6 +701,21 @@ typedef struct {
esp_aes_unwrap_t aes_unwrap; /**< station connect function used when decrypt key data */
esp_hmac_sha256_vector_t hmac_sha256_vector; /**< station connect function used when check MIC */
esp_sha256_prf_t sha256_prf; /**< station connect function used when check MIC */
esp_hmac_md5_t hmac_md5;
esp_hmac_md5_vector_t hamc_md5_vector;
esp_hmac_sha1_t hmac_sha1;
esp_hmac_sha1_vector_t hmac_sha1_vector;
esp_sha1_prf_t sha1_prf;
esp_sha1_vector_t sha1_vector;
esp_pbkdf2_sha1_t pbkdf2_sha1;
esp_rc4_skip_t rc4_skip;
esp_md5_vector_t md5_vector;
esp_aes_encrypt_t aes_encrypt;
esp_aes_encrypt_init_t aes_encrypt_init;
esp_aes_encrypt_deinit_t aes_encrypt_deinit;
esp_aes_decrypt_t aes_decrypt;
esp_aes_decrypt_init_t aes_decrypt_init;
esp_aes_decrypt_deinit_t aes_decrypt_deinit;
}wpa_crypto_funcs_t;
/**
@@ -281,6 +730,18 @@ typedef struct{
esp_hmac_sha256_t hmac_sha256; /**< function used to get attribute */
esp_hmac_sha256_vector_t hmac_sha256_vector; /**< function used to process message when do WPS */
esp_sha256_vector_t sha256_vector; /**< function used to process message when do WPS */
esp_uuid_gen_mac_addr_t uuid_gen_mac_addr;
esp_dh5_free_t dh5_free;
esp_wps_build_assoc_req_ie_t wps_build_assoc_req_ie;
esp_wps_build_assoc_resp_ie_t wps_build_assoc_resp_ie;
esp_wps_build_probe_req_ie_t wps_build_probe_req_ie;
esp_wps_build_public_key_t wps_build_public_key;
esp_wps_enrollee_get_msg_t wps_enrollee_get_msg;
esp_wps_enrollee_process_msg_t wps_enrollee_process_msg;
esp_wps_generate_pin_t wps_generate_pin;
esp_wps_is_selected_pin_registrar_t wps_is_selected_pin_registrar;
esp_wps_is_selected_pbc_registrar_t wps_is_selected_pbc_registrar;
esp_eap_msg_alloc_t eap_msg_alloc;
}wps_crypto_funcs_t;
/**
@@ -298,6 +759,18 @@ typedef struct {
esp_crypto_cipher_deinit_t crypto_cipher_deinit; /**< function used to free context when use TLSV1 */
esp_crypto_mod_exp_t crypto_mod_exp; /**< function used to do key exchange when use TLSV1 */
esp_sha256_vector_t sha256_vector; /**< function used to do X.509v3 certificate parsing and processing */
esp_tls_init_t tls_init;
esp_tls_deinit_t tls_deinit;
esp_eap_peer_blob_init_t eap_peer_blob_init;
esp_eap_peer_blob_deinit_t eap_peer_blob_deinit;
esp_eap_peer_config_init_t eap_peer_config_init;
esp_eap_peer_config_deinit_t eap_peer_config_deinit;
esp_eap_deinit_prev_method_t eap_deinit_prev_method;
esp_eap_peer_get_eap_method_t eap_peer_get_eap_method;
esp_eap_sm_abort_t eap_sm_abort;
esp_eap_sm_build_nak_t eap_sm_build_nak;
esp_eap_sm_build_identity_resp_t eap_sm_build_identity_resp;
esp_eap_msg_alloc_t eap_msg_alloc;
} wpa2_crypto_funcs_t;
/**

12
components/esp32/include/esp_wifi_internal.h Executable file → Normal file
View File

@@ -35,6 +35,7 @@
#include "esp_err.h"
#include "esp_wifi_types.h"
#include "esp_event.h"
#include "esp_wifi.h"
#ifdef __cplusplus
extern "C" {
@@ -126,6 +127,17 @@ esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn);
*/
esp_err_t esp_wifi_internal_set_sta_ip(void);
/**
* @brief Check the MD5 values of the OS adapter header files in IDF and WiFi library
*
* @attention 1. It is used for internal CI version check
*
* @return
* - ESP_OK : succeed
* - ESP_WIFI_INVALID_ARG : MD5 check fail
*/
esp_err_t esp_wifi_internal_osi_funcs_md5_check(const char *md5);
/**
* @brief Allocate a chunk of memory for WiFi driver
*

View File

@@ -0,0 +1,139 @@
// 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.
#ifndef ESP_WIFI_OS_ADAPTER_H_
#define ESP_WIFI_OS_ADAPTER_H_
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000001
#define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF
#define OSI_FUNCS_TIME_BLOCKING 0xffffffff
#define OSI_QUEUE_SEND_FRONT 0
#define OSI_QUEUE_SEND_BACK 1
#define OSI_QUEUE_SEND_OVERWRITE 2
typedef struct {
int32_t _version;
void (*_set_isr)(int32_t n, void *f, void *arg);
void (*_ints_on)(uint32_t mask);
void (*_ints_off)(uint32_t mask);
void *(* _spin_lock_create)(void);
void (* _spin_lock_delete)(void *lock);
uint32_t (*_wifi_int_disable)(void *wifi_int_mux);
void (*_wifi_int_restore)(void *wifi_int_mux, uint32_t tmp);
void (*_task_yield)(void);
void (*_task_yield_from_isr)(void);
void *(*_semphr_create)(uint32_t max, uint32_t init);
void (*_semphr_delete)(void *semphr);
int32_t (*_semphr_take_from_isr)(void *semphr, void *hptw);
int32_t (*_semphr_give_from_isr)(void *semphr, void *hptw);
int32_t (*_semphr_take)(void *semphr, uint32_t block_time_tick);
int32_t (*_semphr_give)(void *semphr);
void *(*_mutex_create)(void);
void *(*_recursive_mutex_create)(void);
void (*_mutex_delete)(void *mutex);
int32_t (*_mutex_lock)(void *mutex);
int32_t (*_mutex_unlock)(void *mutex);
void *(* _queue_create)(uint32_t queue_len, uint32_t item_size);
void (* _queue_delete)(void *queue);
int32_t (* _queue_send)(void *queue, void *item, uint32_t block_time_tick);
int32_t (* _queue_send_from_isr)(void *queue, void *item, void *hptw);
int32_t (* _queue_send_to_back)(void *queue, void *item, uint32_t block_time_tick);
int32_t (* _queue_send_to_front)(void *queue, void *item, uint32_t block_time_tick);
int32_t (* _queue_recv)(void *queue, void *item, uint32_t block_time_tick);
int32_t (* _queue_recv_from_isr)(void *queue, void * const item, int32_t * const hptw);
uint32_t (* _queue_msg_waiting)(void *queue);
void *(* _event_group_create)(void);
void (* _event_group_delete)(void *event);
uint32_t (* _event_group_set_bits)(void *event, uint32_t bits);
uint32_t (* _event_group_clear_bits)(void *event, uint32_t bits);
uint32_t (* _event_group_wait_bits)(void *event, uint32_t bits_to_wait_for, int32_t clear_on_exit, int32_t wait_for_all_bits, uint32_t block_time_tick);
int32_t (* _task_create_pinned_to_core)(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id);
int32_t (* _task_create)(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle);
void (* _task_delete)(void *task_handle);
void (* _task_delay)(uint32_t tick);
int32_t (* _task_ms_to_tick)(uint32_t ms);
void *(* _task_get_current_task)(void);
int32_t (* _task_get_max_priority)(void);
int32_t (* _is_in_isr)(void);
void *(* _malloc)(uint32_t size);
void (* _free)(void *p);
uint32_t (* _get_free_heap_size)(void);
uint32_t (* _rand)(void);
void (* _dport_access_stall_other_cpu_start_wrap)(void);
void (* _dport_access_stall_other_cpu_end_wrap)(void);
int32_t (* _phy_rf_init)(const void * init_data, uint32_t mode, void * calibration_data, uint32_t module);
int32_t (* _phy_rf_deinit)(uint32_t module);
void (* _phy_load_cal_and_init)(uint32_t module);
int32_t (* _read_mac)(uint8_t* mac, uint32_t type);
void (* _timer_init)(void);
void (* _timer_deinit)(void);
void (* _timer_arm)(void *timer, uint32_t tmout, bool repeat);
void (* _timer_disarm)(void *timer);
void (* _timer_done)(void *ptimer);
void (* _timer_setfn)(void *ptimer, void *pfunction, void *parg);
void (* _timer_arm_us)(void *ptimer, uint32_t us, bool repeat);
void (* _periph_module_enable)(uint32_t periph);
void (* _periph_module_disable)(uint32_t periph);
int64_t (* _esp_timer_get_time)(void);
int32_t (* _nvs_set_i8)(uint32_t handle, const char* key, int8_t value);
int32_t (* _nvs_get_i8)(uint32_t handle, const char* key, int8_t* out_value);
int32_t (* _nvs_set_u8)(uint32_t handle, const char* key, uint8_t value);
int32_t (* _nvs_get_u8)(uint32_t handle, const char* key, uint8_t* out_value);
int32_t (* _nvs_set_u16)(uint32_t handle, const char* key, uint16_t value);
int32_t (* _nvs_get_u16)(uint32_t handle, const char* key, uint16_t* out_value);
int32_t (* _nvs_open)(const char* name, uint32_t open_mode, uint32_t *out_handle);
void (* _nvs_close)(uint32_t handle);
int32_t (* _nvs_commit)(uint32_t handle);
int32_t (* _nvs_set_blob)(uint32_t handle, const char* key, const void* value, size_t length);
int32_t (* _nvs_get_blob)(uint32_t handle, const char* key, void* out_value, size_t* length);
int32_t (* _nvs_erase_key)(uint32_t handle, const char* key);
int32_t (* _get_random)(uint8_t *buf, size_t len);
int32_t (* _get_time)(void *t);
unsigned long (* _random)(void);
void (* _log_write)(uint32_t level, const char* tag, const char* format, ...);
uint32_t (* _log_timestamp)(void);
void * (* _malloc_internal)(size_t size);
void * (* _realloc_internal)(void *ptr, size_t size);
void * (* _calloc_internal)(size_t n, size_t size);
void * (* _zalloc_internal)(size_t size);
void * (* _wifi_malloc)(size_t size);
void * (* _wifi_realloc)(void *ptr, size_t size);
void * (* _wifi_calloc)(size_t n, size_t size);
void * (* _wifi_zalloc)(size_t size);
void * (* _wifi_create_queue)(int32_t queue_len, int32_t item_size);
void (* _wifi_delete_queue)(void * queue);
int32_t (* _modem_sleep_enter)(uint32_t module);
int32_t (* _modem_sleep_exit)(uint32_t module);
int32_t (* _modem_sleep_register)(uint32_t module);
int32_t (* _modem_sleep_deregister)(uint32_t module);
void (* _sc_ack_send)(void *param);
void (* _sc_ack_send_stop)(void);
int32_t _magic;
} wifi_osi_funcs_t;
extern wifi_osi_funcs_t g_wifi_osi_funcs;
#ifdef __cplusplus
}
#endif
#endif /* ESP_WIFI_OS_ADAPTER_H_ */

113
components/esp32/include/esp_wifi_types.h Executable file → Normal file
View File

@@ -49,6 +49,7 @@ typedef struct {
char cc[3]; /**< country code string */
uint8_t schan; /**< start channel */
uint8_t nchan; /**< total channel number */
int8_t max_tx_power; /**< maximum tx power */
wifi_country_policy_t policy; /**< country policy */
} wifi_country_t;
@@ -139,7 +140,17 @@ typedef enum {
WIFI_CIPHER_TYPE_UNKNOWN, /**< the cipher type is unknown */
} wifi_cipher_type_t;
/** @brief Description of an WiFi AP */
/**
* @brief WiFi antenna
*
*/
typedef enum {
WIFI_ANT_ANT0, /**< WiFi antenna 0 */
WIFI_ANT_ANT1, /**< WiFi antenna 1 */
WIFI_ANT_MAX, /**< Invalid WiFi antenna */
} wifi_ant_t;
/** @brief Description of a WiFi AP */
typedef struct {
uint8_t bssid[6]; /**< MAC address of AP */
uint8_t ssid[33]; /**< SSID of AP */
@@ -149,12 +160,14 @@ typedef struct {
wifi_auth_mode_t authmode; /**< authmode of AP */
wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of AP */
wifi_cipher_type_t group_cipher; /**< group cipher of AP */
wifi_ant_t ant; /**< antenna used to receive beacon from AP */
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */
uint32_t wps:1; /**< bit: 4 flag to identify if WPS is supported or not */
uint32_t reserved:27; /**< bit: 5..31 reserved */
wifi_country_t country; /**< country information of AP */
} wifi_ap_record_t;
typedef enum {
@@ -230,6 +243,7 @@ typedef union {
/** @brief Description of STA associated with AP */
typedef struct {
uint8_t mac[6]; /**< mac address */
int8_t rssi; /**< current average rssi of sta connected */
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
@@ -305,13 +319,15 @@ typedef struct {
unsigned stbc:2; /**< STBC */
unsigned fec_coding:1; /**< Flag is set for 11n packets which are LDPC */
unsigned sgi:1; /**< SGI */
unsigned noise_floor:8; /**< noise floor */
signed noise_floor:8; /**< noise floor */
unsigned ampdu_cnt:8; /**< ampdu cnt */
unsigned channel:4; /**< which channel this packet in */
unsigned :12; /**< reserve */
unsigned timestamp:32; /**< timestamp */
unsigned :32; /**< reserve */
unsigned channel:4; /**< which primary channel this packet in */
unsigned second_channel:4;/**< which second channel this packet in */
unsigned :8; /**< reserve */
unsigned timestamp:32; /**< timestamp, unit: microsecond */
unsigned :32; /**< reserve */
unsigned :31; /**< reserve */
unsigned ant:1; /**< antenna number from which this packet is received */
unsigned sig_len:12; /**< length of packet */
unsigned :12; /**< reserve */
unsigned rx_state:8; /**< rx state */
@@ -332,6 +348,7 @@ typedef struct {
*/
typedef enum {
WIFI_PKT_MGMT, /**< Management frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */
WIFI_PKT_CTRL, /**< Control frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */
WIFI_PKT_DATA, /**< Data frame, indiciates 'buf' argument is wifi_promiscuous_pkt_t */
WIFI_PKT_MISC, /**< Other type, such as MIMO etc. 'buf' argument is wifi_promiscuous_pkt_t but the payload is zero length. */
} wifi_promiscuous_pkt_type_t;
@@ -339,10 +356,22 @@ typedef enum {
#define WIFI_PROMIS_FILTER_MASK_ALL (0xFFFFFFFF) /**< filter all packets */
#define WIFI_PROMIS_FILTER_MASK_MGMT (1) /**< filter the packets with type of WIFI_PKT_MGMT */
#define WIFI_PROMIS_FILTER_MASK_DATA (1<<1) /**< filter the packets with type of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_MISC (1<<2) /**< filter the packets with type of WIFI_PKT_MISC */
#define WIFI_PROMIS_FILTER_MASK_DATA_MPDU (1<<3) /**< filter the MPDU which is a kind of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU (1<<4) /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_CTRL (1<<1) /**< filter the packets with type of WIFI_PKT_CTRL */
#define WIFI_PROMIS_FILTER_MASK_DATA (1<<2) /**< filter the packets with type of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_MISC (1<<3) /**< filter the packets with type of WIFI_PKT_MISC */
#define WIFI_PROMIS_FILTER_MASK_DATA_MPDU (1<<4) /**< filter the MPDU which is a kind of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU (1<<5) /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */
#define WIFI_PROMIS_CTRL_FILTER_MASK_ALL (0xFF800000) /**< filter all control packets */
#define WIFI_PROMIS_CTRL_FILTER_MASK_WRAPPER (1<<23) /**< filter the control packets with subtype of Control Wrapper */
#define WIFI_PROMIS_CTRL_FILTER_MASK_BAR (1<<24) /**< filter the control packets with subtype of Block Ack Request */
#define WIFI_PROMIS_CTRL_FILTER_MASK_BA (1<<25) /**< filter the control packets with subtype of Block Ack */
#define WIFI_PROMIS_CTRL_FILTER_MASK_PSPOLL (1<<26) /**< filter the control packets with subtype of PS-Poll */
#define WIFI_PROMIS_CTRL_FILTER_MASK_RTS (1<<27) /**< filter the control packets with subtype of RTS */
#define WIFI_PROMIS_CTRL_FILTER_MASK_CTS (1<<28) /**< filter the control packets with subtype of CTS */
#define WIFI_PROMIS_CTRL_FILTER_MASK_ACK (1<<29) /**< filter the control packets with subtype of ACK */
#define WIFI_PROMIS_CTRL_FILTER_MASK_CFEND (1<<30) /**< filter the control packets with subtype of CF-END */
#define WIFI_PROMIS_CTRL_FILTER_MASK_CFENDACK (1<<31) /**< filter the control packets with subtype of CF-END+CF-ACK */
/** @brief Mask for filtering different packet types in promiscuous mode. */
typedef struct {
@@ -353,6 +382,70 @@ typedef struct {
#define WIFI_EVENT_MASK_NONE (0) /**< mask none of the WiFi events */
#define WIFI_EVENT_MASK_AP_PROBEREQRECVED (BIT(0)) /**< mask SYSTEM_EVENT_AP_PROBEREQRECVED event */
/**
* @brief Channel state information(CSI) configuration type
*
*/
typedef struct {
bool lltf_en; /**< enable to receive legacy long training field(lltf) data */
bool htltf_en; /**< enable to receive HT long training field(htltf) data */
bool stbcltf2_en; /**< enable to receive space time block code long training field(stbcltf2) data */
bool manu_scale; /**< manually scale the CSI data by left shifting or automatically scale the CSI data. If set true, please set the shift bits. false: automatically. true: manually */
uint8_t shift; /**< manually left shift bits of the scale of the CSI data. The range of the left shift bits is 0~15 */
} wifi_csi_config_t;
/**
* @brief CSI data type
*
*/
typedef struct {
wifi_pkt_rx_ctrl_t rx_ctrl;/**< received packet radio metadata header of the CSI data */
uint8_t mac[6]; /**< source MAC address of the CSI data */
bool last_word_invalid; /**< last four bytes of the CSI data is invalid or not */
uint8_t *buf; /**< buffer of CSI data */
uint16_t len; /**< length of CSI data */
} wifi_csi_info_t;
/**
* @brief WiFi GPIO configuration for antenna selection
*
*/
typedef struct {
uint8_t gpio_select: 1, /**< Whether this GPIO is connected to external antenna switch */
gpio_num: 7; /**< The GPIO number that connects to external antenna switch */
} wifi_ant_gpio_t;
/**
* @brief WiFi GPIOs configuration for antenna selection
*
*/
typedef struct {
wifi_ant_gpio_t gpio_cfg[4]; /**< The configurations of GPIOs that connect to external antenna switch */
} wifi_ant_gpio_config_t;
/**
* @brief WiFi antenna mode
*
*/
typedef enum {
WIFI_ANT_MODE_ANT0, /**< Enable WiFi antenna 0 only */
WIFI_ANT_MODE_ANT1, /**< Enable WiFi antenna 1 only */
WIFI_ANT_MODE_AUTO, /**< Enable WiFi antenna 0 and 1, automatically select an antenna */
WIFI_ANT_MODE_MAX, /**< Invalid WiFi enabled antenna */
} wifi_ant_mode_t;
/**
* @brief WiFi antenna configuration
*
*/
typedef struct {
wifi_ant_mode_t rx_ant_mode; /**< WiFi antenna mode for receiving */
wifi_ant_t rx_ant_default; /**< Default antenna mode for receiving, it's ignored if rx_ant_mode is not WIFI_ANT_MODE_AUTO */
wifi_ant_mode_t tx_ant_mode; /**< WiFi antenna mode for transmission, it can be set to WIFI_ANT_MODE_AUTO only if rx_ant_mode is set to WIFI_ANT_MODE_AUTO */
uint8_t enabled_ant0: 4, /**< Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT0 */
enabled_ant1: 4; /**< Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT1 */
} wifi_ant_config_t;
#ifdef __cplusplus
}
#endif

View File

@@ -15,6 +15,8 @@
#ifndef ESP_WPA2_H
#define ESP_WPA2_H
#include <stdbool.h>
#include "esp_err.h"
#include "esp_wifi_crypto_types.h"
@@ -121,7 +123,7 @@ void esp_wifi_sta_wpa2_ent_clear_password(void);
* @attention 1. The API only passes the parameter password to the global pointer variable in wpa2 enterprise module.
* @attention 2. The new password is used to substitute the old password when eap-mschapv2 failure request message with error code ERROR_PASSWD_EXPIRED is received.
*
* @param password: point to address where stores the password;
* @param new_password: point to address where stores the password;
* @param len: length of password
*
* @return
@@ -130,7 +132,7 @@ void esp_wifi_sta_wpa2_ent_clear_password(void);
* - ESP_ERR_NO_MEM: fail(internal memory malloc fail)
*/
esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(const unsigned char *password, int len);
esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(const unsigned char *new_password, int len);
/**
* @brief Clear new password for MSCHAPv2 method..
@@ -144,12 +146,12 @@ void esp_wifi_sta_wpa2_ent_clear_new_password(void);
* @attention 2. The ca_cert should be zero terminated.
*
* @param ca_cert: point to address where stores the CA certificate;
* @param len: length of ca_cert
* @param ca_cert_len: length of ca_cert
*
* @return
* - ESP_OK: succeed
*/
esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(const unsigned char *ca_cert, int len);
esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(const unsigned char *ca_cert, int ca_cert_len);
/**
* @brief Clear CA certificate for PEAP/TTLS method.

View File

@@ -56,14 +56,33 @@ typedef enum wps_type {
extern const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs;
#define WPS_MAX_MANUFACTURER_LEN 65
#define WPS_MAX_MODEL_NUMBER_LEN 33
#define WPS_MAX_MODEL_NAME_LEN 33
#define WPS_MAX_DEVICE_NAME_LEN 33
typedef struct {
char manufacturer[WPS_MAX_MANUFACTURER_LEN]; /*!< Manufacturer, null-terminated string. The default manufcturer is used if the string is empty */
char model_number[WPS_MAX_MODEL_NUMBER_LEN]; /*!< Model number, null-terminated string. The default model number is used if the string is empty */
char model_name[WPS_MAX_MODEL_NAME_LEN]; /*!< Model name, null-terminated string. The default model name is used if the string is empty */
char device_name[WPS_MAX_DEVICE_NAME_LEN]; /*!< Device name, null-terminated string. The default device name is used if the string is empty */
} wps_factory_information_t;
typedef struct {
wps_type_t wps_type;
const wps_crypto_funcs_t *crypto_funcs;
}esp_wps_config_t;
wps_factory_information_t factory_info;
} esp_wps_config_t;
#define WPS_CONFIG_INIT_DEFAULT(type) { \
.wps_type = type, \
.crypto_funcs = &g_wifi_default_wps_crypto_funcs, \
.factory_info = { \
.manufacturer = "ESPRESSIF", \
.model_number = "ESP32", \
.model_name = "ESPRESSIF IOT", \
.device_name = "ESP STATION", \
} \
}
/**

View File

@@ -243,7 +243,10 @@ int esp_aes_crypt_ctr( esp_aes_context *ctx,
* \param input Plaintext block
* \param output Output (ciphertext) block
*/
void esp_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] );
int esp_internal_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] );
/** Deprecated, see esp_aes_internal_encrypt */
void esp_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ) __attribute__((deprecated));
/**
* \brief Internal AES block decryption function
@@ -254,7 +257,10 @@ void esp_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsig
* \param input Ciphertext block
* \param output Output (plaintext) block
*/
void esp_aes_decrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] );
int esp_internal_aes_decrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] );
/** Deprecated, see esp_aes_internal_decrypt */
void esp_aes_decrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ) __attribute__((deprecated));
#ifdef __cplusplus
}

View File

@@ -301,6 +301,15 @@ typedef struct _ETSTIMER_ {
*/
void ets_timer_init(void);
/**
* @brief In FreeRTOS, please call FreeRTOS apis, never call this api.
*
* @param None
*
* @return None
*/
void ets_timer_deinit(void);
/**
* @brief Arm an ets timer, this timer range is 640 us to 429496 ms.
* In FreeRTOS, please call FreeRTOS apis, never call this api.

0
components/esp32/include/rom/md5_hash.h Executable file → Normal file
View File

0
components/esp32/include/rom/queue.h Executable file → Normal file
View File

View File

@@ -117,6 +117,8 @@ extern "C" {
#define ESP_ROM_SPIFLASH_WR_PROTECT (ESP_ROM_SPIFLASH_BP0|ESP_ROM_SPIFLASH_BP1|ESP_ROM_SPIFLASH_BP2)
#define ESP_ROM_SPIFLASH_QE BIT9
#define FLASH_ID_GD25LQ32C 0xC86016
typedef enum {
ESP_ROM_SPIFLASH_QIO_MODE = 0,
ESP_ROM_SPIFLASH_QOUT_MODE,

0
components/esp32/include/xtensa/board.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/c6x-compat.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/cacheasm.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/cacheattrasm.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/core-macros.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/coreasm.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/corebits.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/debugfs.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/feedback.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/gdbio.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/hal.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/jtag-xtensa.h Executable file → Normal file
View File

View File

View File

0
components/esp32/include/xtensa/lcd-splc780d.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/overlay.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/overlay_os_asm.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/sim.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/simboard.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/simcall-errno.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/simcall-fcntl.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/simcall.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/specreg.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/trax-api.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/trax-core-config.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/trax-proto.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/trax-util.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/trax.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/traxfile.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/traxreg.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/uart-16550-board.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/uart-16550.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/udma.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xdm-regs.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xmon.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xmp-library.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_common.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_cond.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_errors.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_event.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_internal.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_msgq.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_mutex.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_params.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_regaccess.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_semaphore.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_stopwatch.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_syslog.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_thread.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_timer.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xos_types.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xt_perf_consts.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xt_perfmon.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xt_profiling.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xt_reftb.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xtav110.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xtav110/xtensa/board.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xtav200.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xtav200/xtensa/board.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xtav60.h Executable file → Normal file
View File

0
components/esp32/include/xtensa/xtav60/xtensa/board.h Executable file → Normal file
View File

View File

0
components/esp32/include/xtensa/xtbsp.h Executable file → Normal file
View File

Some files were not shown because too many files have changed in this diff Show More