mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/esp8266: required vendor RTOS SDK components added
This commit is contained in:
parent
f397a74948
commit
28ea0a0914
@ -60,6 +60,12 @@ PSEUDOMODULES += esp_sw_timer
|
||||
PSEUDOMODULES += esp_spiffs
|
||||
|
||||
USEMODULE += esp_freertos
|
||||
USEMODULE += esp_idf
|
||||
USEMODULE += esp_idf_esp8266
|
||||
USEMODULE += esp_idf_nvs_flash
|
||||
USEMODULE += esp_idf_spi_flash
|
||||
USEMODULE += esp_idf_util
|
||||
USEMODULE += esp_idf_wpa_supplicant_crypto
|
||||
USEMODULE += mtd
|
||||
USEMODULE += newlib
|
||||
USEMODULE += newlib_nano
|
||||
|
4
cpu/esp8266/vendor/Makefile
vendored
4
cpu/esp8266/vendor/Makefile
vendored
@ -1,7 +1,7 @@
|
||||
# Add a list of subdirectories, that should also be built:
|
||||
DIRS += esp
|
||||
DIRS += esp-idf
|
||||
|
||||
ifeq ($(ENABLE_GDBSTUB), 1)
|
||||
ifneq (, $(filter esp_gdbstub, $(USEMODULE)))
|
||||
DIRS += esp-gdbstub
|
||||
endif
|
||||
|
||||
|
4
cpu/esp8266/vendor/README.md
vendored
4
cpu/esp8266/vendor/README.md
vendored
@ -8,6 +8,6 @@ The files that are part of [esp-open-rtos](https://github.com/SuperHouse/esp-ope
|
||||
|
||||
The files in this directory are a modified version of [esp-gdbstub](https://github.com/espressif/esp-gdbstub). The files are copyright of Espressif Systems (Shanghai) Pte., Ltd. and are licensed under the Espressif MIT license.
|
||||
|
||||
### espressif
|
||||
### esp-idf
|
||||
|
||||
The files in this directory are either from the [ESP8266_NONOS_SDK](https://github.com/espressif/ESP8266_NONOS_SDK.git) or from the [ESP_RTOS_SDK](https://github.com/espressif/ESP8266_RTOS_SDK.git) for ESP8266. All of these files are copyright of Espressif Systems (Shanghai) Pte., Ltd. Please note the copyright notice in these files.
|
||||
The files in this directory and all subdirectories are from the [ESP8266 RTOS SDK](https://github.com/espressif/ESP8266_RTOS_SDK), the official development framework for ESP8266. All of these files are under copyright of Espressif Systems (Shanghai) PTE LTD or their respective owners and licensed under the Apache License, Version 2.0. Please refer the copyright notice in these files for details.
|
||||
|
13
cpu/esp8266/vendor/esp-idf/Makefile
vendored
Normal file
13
cpu/esp8266/vendor/esp-idf/Makefile
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
MODULE=esp_idf
|
||||
|
||||
DIRS += esp8266/source
|
||||
DIRS += nvs_flash/src
|
||||
DIRS += spi_flash
|
||||
DIRS += util/src
|
||||
DIRS += wpa_supplicant
|
||||
|
||||
ifneq (, $(filter esp_idf_heap, $(USEMODULE)))
|
||||
DIRS += heap/src
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
1
cpu/esp8266/vendor/esp-idf/README.md
vendored
Normal file
1
cpu/esp8266/vendor/esp-idf/README.md
vendored
Normal file
@ -0,0 +1 @@
|
||||
The files in this directory and all subdirectories are from the [ESP8266 RTOS SDK](https://github.com/espressif/ESP8266_RTOS_SDK), the official development framework for ESP8266. All of these files are copyright of Espressif Systems (Shanghai) PTE LTD or their respective owners and licensed under the Apache License, Version 2.0. Please refer the copyright notice in these files for details.
|
181
cpu/esp8266/vendor/esp-idf/bootloader_support/include/esp_image_format.h
vendored
Normal file
181
cpu/esp8266/vendor/esp-idf/bootloader_support/include/esp_image_format.h
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#define ESP_ERR_IMAGE_BASE 0x2000
|
||||
#define ESP_ERR_IMAGE_FLASH_FAIL (ESP_ERR_IMAGE_BASE + 1)
|
||||
#define ESP_ERR_IMAGE_INVALID (ESP_ERR_IMAGE_BASE + 2)
|
||||
|
||||
/* Support for app/bootloader image parsing
|
||||
Can be compiled as part of app or bootloader code.
|
||||
*/
|
||||
|
||||
/* SPI flash mode, used in esp_image_header_t */
|
||||
typedef enum {
|
||||
ESP_IMAGE_SPI_MODE_QIO,
|
||||
ESP_IMAGE_SPI_MODE_QOUT,
|
||||
ESP_IMAGE_SPI_MODE_DIO,
|
||||
ESP_IMAGE_SPI_MODE_DOUT,
|
||||
ESP_IMAGE_SPI_MODE_FAST_READ,
|
||||
ESP_IMAGE_SPI_MODE_SLOW_READ
|
||||
} esp_image_spi_mode_t;
|
||||
|
||||
/* SPI flash clock frequency */
|
||||
typedef enum {
|
||||
ESP_IMAGE_SPI_SPEED_40M,
|
||||
ESP_IMAGE_SPI_SPEED_26M,
|
||||
ESP_IMAGE_SPI_SPEED_20M,
|
||||
ESP_IMAGE_SPI_SPEED_80M = 0xF
|
||||
} esp_image_spi_freq_t;
|
||||
|
||||
#ifdef CONFIG_TARGET_PLATFORM_ESP32
|
||||
/* Supported SPI flash sizes */
|
||||
typedef enum {
|
||||
ESP_IMAGE_FLASH_SIZE_1MB = 0,
|
||||
ESP_IMAGE_FLASH_SIZE_2MB,
|
||||
ESP_IMAGE_FLASH_SIZE_4MB,
|
||||
ESP_IMAGE_FLASH_SIZE_8MB,
|
||||
ESP_IMAGE_FLASH_SIZE_16MB,
|
||||
ESP_IMAGE_FLASH_SIZE_MAX
|
||||
} esp_image_flash_size_t;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
|
||||
/* Supported SPI flash sizes */
|
||||
typedef enum {
|
||||
ESP_IMAGE_FLASH_SIZE_512KB = 0,
|
||||
ESP_IMAGE_FLASH_SIZE_256KB,
|
||||
ESP_IMAGE_FLASH_SIZE_1MB,
|
||||
ESP_IMAGE_FLASH_SIZE_2MB,
|
||||
ESP_IMAGE_FLASH_SIZE_4MB,
|
||||
ESP_IMAGE_FLASH_SIZE_2MB_C1,
|
||||
ESP_IMAGE_FLASH_SIZE_4MB_C1,
|
||||
ESP_IMAGE_FLASH_SIZE_8MB = 8,
|
||||
ESP_IMAGE_FLASH_SIZE_16MB,
|
||||
ESP_IMAGE_FLASH_SIZE_MAX
|
||||
} esp_image_flash_size_t;
|
||||
|
||||
#endif
|
||||
|
||||
#define ESP_IMAGE_HEADER_MAGIC 0xE9
|
||||
|
||||
/* Main header of binary image */
|
||||
typedef struct {
|
||||
uint8_t magic;
|
||||
uint8_t segment_count;
|
||||
/* flash read mode (esp_image_spi_mode_t as uint8_t) */
|
||||
uint8_t spi_mode;
|
||||
/* flash frequency (esp_image_spi_freq_t as uint8_t) */
|
||||
uint8_t spi_speed: 4;
|
||||
/* flash chip size (esp_image_flash_size_t as uint8_t) */
|
||||
uint8_t spi_size: 4;
|
||||
uint32_t entry_addr;
|
||||
|
||||
#ifdef CONFIG_TARGET_PLATFORM_ESP32
|
||||
/* WP pin when SPI pins set via efuse (read by ROM bootloader, the IDF bootloader uses software to configure the WP
|
||||
* pin and sets this field to 0xEE=disabled) */
|
||||
uint8_t wp_pin;
|
||||
/* Drive settings for the SPI flash pins (read by ROM bootloader) */
|
||||
uint8_t spi_pin_drv[3];
|
||||
/* Reserved bytes in ESP32 additional header space, currently unused */
|
||||
uint8_t reserved[11];
|
||||
/* If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum. Included in image length. This digest
|
||||
* is separate to secure boot and only used for detecting corruption. For secure boot signed images, the signature
|
||||
* is appended after this (and the simple hash is included in the signed data). */
|
||||
uint8_t hash_appended;
|
||||
#endif
|
||||
} __attribute__((packed)) esp_image_header_t;
|
||||
|
||||
#ifdef CONFIG_TARGET_PLATFORM_ESP32
|
||||
_Static_assert(sizeof(esp_image_header_t) == 24, "binary image header should be 24 bytes");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
|
||||
_Static_assert(sizeof(esp_image_header_t) == 8, "binary image header should be 8 bytes");
|
||||
#endif
|
||||
|
||||
/* Header of binary image segment */
|
||||
typedef struct {
|
||||
uint32_t load_addr;
|
||||
uint32_t data_len;
|
||||
} esp_image_segment_header_t;
|
||||
|
||||
#define ESP_IMAGE_MAX_SEGMENTS 16
|
||||
|
||||
/* Structure to hold on-flash image metadata */
|
||||
typedef struct {
|
||||
uint32_t start_addr; /* Start address of image */
|
||||
esp_image_header_t image; /* Header for entire image */
|
||||
esp_image_segment_header_t segments[ESP_IMAGE_MAX_SEGMENTS]; /* Per-segment header data */
|
||||
uint32_t segment_data[ESP_IMAGE_MAX_SEGMENTS]; /* Data offsets for each segment */
|
||||
uint32_t image_len; /* Length of image on flash, in bytes */
|
||||
} esp_image_metadata_t;
|
||||
|
||||
/* Mode selection for esp_image_load() */
|
||||
typedef enum {
|
||||
ESP_IMAGE_VERIFY, /* Verify image contents, load metadata. Print errorsors. */
|
||||
ESP_IMAGE_VERIFY_SILENT, /* Verify image contents, load metadata. Don't print errors. */
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
ESP_IMAGE_LOAD, /* Verify image contents, load to memory. Print errors. */
|
||||
#endif
|
||||
} esp_image_load_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Verify and (optionally, in bootloader mode) load an app image.
|
||||
*
|
||||
* If encryption is enabled, data will be transparently decrypted.
|
||||
*
|
||||
* @param mode Mode of operation (verify, silent verify, or load).
|
||||
* @param part Partition to load the app from.
|
||||
* @param[inout] data Pointer to the image metadata structure which is be filled in by this function. 'start_addr' member should be set (to the start address of the image.) Other fields will all be initialised by this function.
|
||||
*
|
||||
* Image validation checks:
|
||||
* - Magic byte.
|
||||
* - Partition smaller than 16MB.
|
||||
* - All segments & image fit in partition.
|
||||
* - 8 bit image checksum is valid.
|
||||
* - SHA-256 of image is valid (if image has this appended).
|
||||
* - (Signature) if signature verification is enabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if verify or load was successful
|
||||
* - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs
|
||||
* - ESP_ERR_IMAGE_INVALID if the image appears invalid.
|
||||
* - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid.
|
||||
*/
|
||||
esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data);
|
||||
|
||||
/**
|
||||
* @brief Verify the bootloader image.
|
||||
*
|
||||
* @param[out] If result is ESP_OK and this pointer is non-NULL, it
|
||||
* will be set to the length of the bootloader image.
|
||||
*
|
||||
* @return As per esp_image_load_metadata().
|
||||
*/
|
||||
esp_err_t esp_image_verify_bootloader(uint32_t *length);
|
||||
|
||||
typedef struct {
|
||||
uint32_t drom_addr;
|
||||
uint32_t drom_load_addr;
|
||||
uint32_t drom_size;
|
||||
uint32_t irom_addr;
|
||||
uint32_t irom_load_addr;
|
||||
uint32_t irom_size;
|
||||
} esp_image_flash_mapping_t;
|
45
cpu/esp8266/vendor/esp-idf/esp8266/include/esp8266/rom_functions.h
vendored
Normal file
45
cpu/esp8266/vendor/esp-idf/esp8266/include/esp8266/rom_functions.h
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef _ROM_FUNCTIONS_H
|
||||
#define _ROM_FUNCTIONS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define ROM_FLASH_BUF_DECLARE(__name, __size) uint8_t __name[__size] __attribute__((aligned(4)))
|
||||
|
||||
typedef struct esp_spi_flash_chip {
|
||||
uint32_t deviceId;
|
||||
uint32_t chip_size; // chip size in byte
|
||||
uint32_t block_size;
|
||||
uint32_t sector_size;
|
||||
uint32_t page_size;
|
||||
uint32_t status_mask;
|
||||
} esp_spi_flash_chip_t;
|
||||
|
||||
extern esp_spi_flash_chip_t flashchip;
|
||||
|
||||
uint32_t Wait_SPI_Idle(esp_spi_flash_chip_t *chip);
|
||||
|
||||
void uart_div_modify(uint32_t uart_no, uint32_t baud_div);
|
||||
|
||||
int ets_io_vprintf(int (*putc)(int), const char* fmt, va_list ap);
|
||||
|
||||
void system_soft_wdt_feed(void);
|
||||
|
||||
void Cache_Read_Enable_New(void);
|
||||
|
||||
int SPI_page_program(esp_spi_flash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len);
|
||||
int SPI_read_data(esp_spi_flash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len);
|
||||
int SPI_write_enable(esp_spi_flash_chip_t *chip);
|
||||
int SPI_sector_erase(esp_spi_flash_chip_t *chip, uint32_t sect_addr);
|
||||
int SPI_write_status(esp_spi_flash_chip_t *chip, uint32_t status);
|
||||
int SPI_read_status(esp_spi_flash_chip_t *chip, uint32_t *status);
|
||||
int Enable_QMode(esp_spi_flash_chip_t *chip);
|
||||
|
||||
int SPIWrite(uint32_t addr, const uint8_t *src, uint32_t size);
|
||||
int SPIRead(uint32_t addr, void *dst, uint32_t size);
|
||||
int SPIEraseSector(uint32_t sector_num);
|
||||
|
||||
void Cache_Read_Disable(void);
|
||||
void Cache_Read_Enable(uint8_t map, uint8_t p, uint8_t v);
|
||||
|
||||
#endif
|
195
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_event.h
vendored
Normal file
195
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_event.h
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
// 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_EVENT_H__
|
||||
#define __ESP_EVENT_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#ifndef RIOT_VERSION
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ESP_EVENT_IPV6 LWIP_IPV6
|
||||
|
||||
typedef enum {
|
||||
SYSTEM_EVENT_WIFI_READY = 0, /**< ESP8266 WiFi ready */
|
||||
SYSTEM_EVENT_SCAN_DONE, /**< ESP8266 finish scanning AP */
|
||||
SYSTEM_EVENT_STA_START, /**< ESP8266 station start */
|
||||
SYSTEM_EVENT_STA_STOP, /**< ESP8266 station stop */
|
||||
SYSTEM_EVENT_STA_CONNECTED, /**< ESP8266 station connected to AP */
|
||||
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP8266 station disconnected from AP */
|
||||
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP8266 station changed */
|
||||
SYSTEM_EVENT_STA_GOT_IP, /**< ESP8266 station got IP from connected AP */
|
||||
SYSTEM_EVENT_STA_LOST_IP, /**< ESP8266 station lost IP and the IP is reset to 0 */
|
||||
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP8266 station wps succeeds in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP8266 station wps fails in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP8266 station wps timeout in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP8266 station wps pin code in enrollee mode */
|
||||
SYSTEM_EVENT_AP_START, /**< ESP8266 soft-AP start */
|
||||
SYSTEM_EVENT_AP_STOP, /**< ESP8266 soft-AP stop */
|
||||
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP8266 soft-AP */
|
||||
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP8266 soft-AP */
|
||||
SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP8266 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, /**< ESP8266 station or ap or ethernet interface v6IP addr is preferred */
|
||||
SYSTEM_EVENT_ETH_START, /**< ESP8266 ethernet start */
|
||||
SYSTEM_EVENT_ETH_STOP, /**< ESP8266 ethernet stop */
|
||||
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP8266 ethernet phy link up */
|
||||
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP8266 ethernet phy link down */
|
||||
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP8266 ethernet got IP from connected AP */
|
||||
SYSTEM_EVENT_MAX
|
||||
} system_event_id_t;
|
||||
|
||||
/* add this macro define for compatible with old IDF version */
|
||||
#ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
|
||||
#define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
WPS_FAIL_REASON_NORMAL = 0, /**< ESP8266 WPS normal fail reason */
|
||||
WPS_FAIL_REASON_RECV_M2D, /**< ESP8266 WPS receive M2D frame */
|
||||
WPS_FAIL_REASON_MAX
|
||||
}system_event_sta_wps_fail_reason_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t status; /**< status of scanning APs */
|
||||
uint8_t number;
|
||||
uint8_t scan_id;
|
||||
} system_event_sta_scan_done_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t ssid[32]; /**< SSID of connected AP */
|
||||
uint8_t ssid_len; /**< SSID length of connected AP */
|
||||
uint8_t bssid[6]; /**< BSSID of connected AP*/
|
||||
uint8_t channel; /**< channel of connected AP*/
|
||||
wifi_auth_mode_t authmode;
|
||||
} system_event_sta_connected_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t ssid[32]; /**< SSID of disconnected AP */
|
||||
uint8_t ssid_len; /**< SSID length of disconnected AP */
|
||||
uint8_t bssid[6]; /**< BSSID of disconnected AP */
|
||||
uint8_t reason; /**< reason of disconnection */
|
||||
} system_event_sta_disconnected_t;
|
||||
|
||||
typedef struct {
|
||||
wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
|
||||
wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
|
||||
} system_event_sta_authmode_change_t;
|
||||
|
||||
#ifndef RIOT_VERSION
|
||||
typedef struct {
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
bool ip_changed;
|
||||
} system_event_sta_got_ip_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
|
||||
} system_event_sta_wps_er_pin_t;
|
||||
|
||||
#ifndef RIOT_VERSION
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t if_index;
|
||||
tcpip_adapter_ip6_info_t ip6_info;
|
||||
} system_event_got_ip6_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station connected to ESP8266 soft-AP */
|
||||
uint8_t aid; /**< the aid that ESP8266 soft-AP gives to the station connected to */
|
||||
} system_event_ap_staconnected_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station disconnects to ESP8266 soft-AP */
|
||||
uint8_t aid; /**< the aid that ESP8266 soft-AP gave to the station disconnects to */
|
||||
} system_event_ap_stadisconnected_t;
|
||||
|
||||
typedef struct {
|
||||
int rssi; /**< Received probe request signal strength */
|
||||
uint8_t mac[6]; /**< MAC address of the station which send probe request */
|
||||
} system_event_ap_probe_req_rx_t;
|
||||
|
||||
typedef union {
|
||||
system_event_sta_connected_t connected; /**< ESP8266 station connected to AP */
|
||||
system_event_sta_disconnected_t disconnected; /**< ESP8266 station disconnected to AP */
|
||||
system_event_sta_scan_done_t scan_done; /**< ESP8266 station scan (APs) done */
|
||||
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP8266 station connected to changed */
|
||||
#ifndef RIOT_VERSION
|
||||
system_event_sta_got_ip_t got_ip; /**< ESP8266 station got IP, first time got IP or when IP is changed */
|
||||
#endif
|
||||
system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP8266 station WPS enrollee mode PIN code received */
|
||||
system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP8266 station WPS enrollee mode failed reason code received */
|
||||
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP8266 soft-AP */
|
||||
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP8266 soft-AP */
|
||||
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP8266 soft-AP receive probe request packet */
|
||||
#ifndef RIOT_VERSION
|
||||
system_event_got_ip6_t got_ip6; /**< ESP8266 station or ap or ethernet ipv6 addr state change to preferred */
|
||||
#endif
|
||||
} system_event_info_t;
|
||||
|
||||
typedef struct {
|
||||
system_event_id_t event_id; /**< event ID */
|
||||
system_event_info_t event_info; /**< event information */
|
||||
} system_event_t;
|
||||
|
||||
typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Send a event to event task
|
||||
*
|
||||
* @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
|
||||
*
|
||||
* @param system_event_t * event : event
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
esp_err_t esp_event_send(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Default event handler for system events
|
||||
*
|
||||
* This function performs default handling of system events.
|
||||
* When using esp_event_loop APIs, it is called automatically before invoking the user-provided
|
||||
* callback function.
|
||||
*
|
||||
* Applications which implement a custom event loop must call this function
|
||||
* as part of event processing.
|
||||
*
|
||||
* @param event pointer to event to be handled
|
||||
* @return ESP_OK if an event was handled successfully
|
||||
*/
|
||||
esp_err_t esp_event_process_default(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
|
||||
*
|
||||
*/
|
||||
void esp_event_set_default_wifi_handlers(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_EVENT_H__ */
|
83
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_event_loop.h
vendored
Normal file
83
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_event_loop.h
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
// 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_EVENT_LOOP_H__
|
||||
#define __ESP_EVENT_LOOP_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#define EVENT_LOOP_STACKSIZE CONFIG_EVENT_LOOP_STACK_SIZE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Application specified event callback function
|
||||
*
|
||||
* @param void *ctx : reserved for user
|
||||
* @param system_event_t *event : event type defined in this file
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Initialize event loop
|
||||
* Create the event handler and task
|
||||
*
|
||||
* @param system_event_cb_t cb : application specified event callback, it can be modified by call esp_event_set_cb
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Set application specified event callback function
|
||||
*
|
||||
* @attention 1. If cb is NULL, means application don't need to handle
|
||||
* If cb is not NULL, it will be call when an event is received, after the default event callback is completed
|
||||
*
|
||||
* @param system_event_cb_t cb : callback
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return system_event_cb_t : old callback
|
||||
*/
|
||||
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Get the queue used by event loop
|
||||
*
|
||||
* @attention : currently this API is used to initialize "q" parameter
|
||||
* of wifi_init structure.
|
||||
*
|
||||
* @return QueueHandle_t : event queue handle
|
||||
*/
|
||||
QueueHandle_t esp_event_loop_get_queue(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_EVENT_LOOP_H__ */
|
171
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_phy_init.h
vendored
Normal file
171
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_phy_init.h
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file PHY init parameters and API
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure holding PHY init parameters
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t params[128]; /*!< opaque PHY initialization parameters */
|
||||
} esp_phy_init_data_t;
|
||||
|
||||
/**
|
||||
* @brief Opaque PHY calibration data
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t rf_cal_data[128]; /*!< calibration data */
|
||||
uint32_t rx_gain_dc_table[125];
|
||||
} esp_phy_calibration_data_t;
|
||||
|
||||
typedef enum {
|
||||
PHY_RF_CAL_PARTIAL = 0x00000000, /*!< Do part of RF calibration. This should be used after power-on reset. */
|
||||
PHY_RF_CAL_NONE = 0x00000001, /*!< Don't do any RF calibration. This mode is only suggested to be used after deep sleep reset. */
|
||||
PHY_RF_CAL_FULL = 0x00000002 /*!< Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once. */
|
||||
} esp_phy_calibration_mode_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Modules for modem sleep
|
||||
*/
|
||||
typedef enum {
|
||||
MODEM_WIFI_STATION_MODULE, //!< Wi-Fi Station used
|
||||
MODEM_WIFI_SOFTAP_MODULE, //!< Wi-Fi SoftAP used
|
||||
MODEM_WIFI_SNIFFER_MODULE, //!< Wi-Fi Sniffer used
|
||||
MODEM_USER_MODULE, //!< User used
|
||||
MODEM_MODULE_COUNT //!< Number of items
|
||||
} modem_sleep_module_t;
|
||||
|
||||
/**
|
||||
* @brief Module WIFI mask for medem sleep
|
||||
*/
|
||||
#define MODEM_WIFI_MASK ((1<<MODEM_WIFI_STATION_MODULE) | \
|
||||
(1<<MODEM_WIFI_SOFTAP_MODULE) | \
|
||||
(1<<MODEM_WIFI_SNIFFER_MODULE))
|
||||
|
||||
/**
|
||||
* @brief Modules needing to call phy_rf_init
|
||||
*/
|
||||
typedef enum {
|
||||
PHY_WIFI_MODULE, //!< Wi-Fi used
|
||||
PHY_MODEM_MODULE, //!< Modem sleep used
|
||||
PHY_MODULE_COUNT //!< Number of items
|
||||
} phy_rf_module_t;
|
||||
|
||||
/**
|
||||
* @brief Get PHY init data
|
||||
*
|
||||
* If "Use a partition to store PHY init data" option is set in menuconfig,
|
||||
* This function will load PHY init data from a partition. Otherwise,
|
||||
* PHY init data will be compiled into the application itself, and this function
|
||||
* will return a pointer to PHY init data located in read-only memory (DROM).
|
||||
*
|
||||
* If "Use a partition to store PHY init data" option is enabled, this function
|
||||
* may return NULL if the data loaded from flash is not valid.
|
||||
*
|
||||
* @note Call esp_phy_release_init_data to release the pointer obtained using
|
||||
* this function after the call to esp_wifi_init.
|
||||
*
|
||||
* @return pointer to PHY init data structure
|
||||
*/
|
||||
const esp_phy_init_data_t *esp_phy_get_init_data(void);
|
||||
|
||||
/**
|
||||
* @brief Release PHY init data
|
||||
* @param data pointer to PHY init data structure obtained from
|
||||
* esp_phy_get_init_data function
|
||||
*/
|
||||
void esp_phy_release_init_data(const esp_phy_init_data_t *data);
|
||||
|
||||
/**
|
||||
* @brief Function called by esp_phy_init to load PHY calibration data
|
||||
*
|
||||
* This is a convenience function which can be used to load PHY calibration
|
||||
* data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
|
||||
* function.
|
||||
*
|
||||
* If calibration data is not present in the NVS, or
|
||||
* data is not valid (was obtained for a chip with a different MAC address,
|
||||
* or obtained for a different version of software), this function will
|
||||
* return an error.
|
||||
*
|
||||
* @param out_cal_data pointer to calibration data structure to be filled with
|
||||
* loaded data.
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t *out_cal_data);
|
||||
|
||||
/**
|
||||
* @brief Function called by esp_phy_init to store PHY calibration data
|
||||
*
|
||||
* This is a convenience function which can be used to store PHY calibration
|
||||
* data to the NVS. Calibration data is returned by phy function.
|
||||
* Data saved using this function to the NVS can later be loaded using
|
||||
* esp_phy_store_cal_data_to_nvs function.
|
||||
*
|
||||
* @param cal_data pointer to calibration data which has to be saved.
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t *cal_data);
|
||||
|
||||
/**
|
||||
* @brief Initialize PHY and RF module
|
||||
*
|
||||
* PHY and RF module should be initialized in order to use WiFi.
|
||||
* Now PHY and RF initializing job is done automatically when start WiFi. Users should not
|
||||
* call this API in their application.
|
||||
*
|
||||
* @param init_data PHY parameters. Default set of parameters can
|
||||
* be obtained by calling esp_phy_get_default_init_data
|
||||
* function.
|
||||
* @param mode Calibration mode (Full, partial, or no calibration)
|
||||
* @param[inout] calibration_data
|
||||
* @return ESP_OK on success.
|
||||
* @return ESP_FAIL on fail.
|
||||
*/
|
||||
esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibration_mode_t mode,
|
||||
esp_phy_calibration_data_t *calibration_data, phy_rf_module_t module);
|
||||
|
||||
/**
|
||||
* @brief De-initialize PHY and RF module
|
||||
*
|
||||
* PHY module should be de-initialized in order to shutdown WiFi.
|
||||
* Now PHY and RF de-initializing job is done automatically when stop WiFi. Users should not
|
||||
* call this API in their application.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
*/
|
||||
esp_err_t esp_phy_rf_deinit(phy_rf_module_t module);
|
||||
|
||||
/**
|
||||
* @brief Load calibration data from NVS and initialize PHY and RF module
|
||||
*/
|
||||
void esp_phy_load_cal_and_init(phy_rf_module_t module);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
888
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_wifi.h
vendored
Normal file
888
cpu/esp8266/vendor/esp-idf/esp8266/include/esp_wifi.h
vendored
Normal file
@ -0,0 +1,888 @@
|
||||
// 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.
|
||||
|
||||
|
||||
/* Notes about WiFi Programming
|
||||
*
|
||||
* The ESP8266 WiFi programming model can be depicted as following picture:
|
||||
*
|
||||
*
|
||||
* default handler user handler
|
||||
* ------------- --------------- ---------------
|
||||
* | | event | | callback or | |
|
||||
* | tcpip | ---------> | event | ----------> | application |
|
||||
* | stack | | task | event | task |
|
||||
* |-----------| |-------------| |-------------|
|
||||
* /|\ |
|
||||
* | |
|
||||
* event | |
|
||||
* | |
|
||||
* | |
|
||||
* --------------- |
|
||||
* | | |
|
||||
* | WiFi Driver |/__________________|
|
||||
* | |\ API call
|
||||
* | |
|
||||
* |-------------|
|
||||
*
|
||||
* The WiFi driver can be consider as black box, it knows nothing about the high layer code, such as
|
||||
* TCPIP stack, application task, event task etc, all it can do is to receive API call from high layer
|
||||
* or post event queue to a specified Queue, which is initialized by API esp_wifi_init().
|
||||
*
|
||||
* The event task is a daemon task, which receives events from WiFi driver or from other subsystem, such
|
||||
* as TCPIP stack, event task will call the default callback function on receiving the event. For example,
|
||||
* on receiving event SYSTEM_EVENT_STA_CONNECTED, it will call tcpip_adapter_start() to start the DHCP
|
||||
* client in it's default handler.
|
||||
*
|
||||
* Application can register it's own event callback function by API esp_event_init, then the application callback
|
||||
* function will be called after the default callback. Also, if application doesn't want to execute the callback
|
||||
* in the event task, what it needs to do is to post the related event to application task in the application callback function.
|
||||
*
|
||||
* The application task (code) generally mixes all these thing together, it calls APIs to init the system/WiFi and
|
||||
* handle the events when necessary.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ESP_WIFI_H__
|
||||
#define __ESP_WIFI_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_wifi_os_adapter.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ESP_ERR_WIFI_NOT_INIT (ESP_ERR_WIFI_BASE + 1) /*!< WiFi driver was not installed by esp_wifi_init */
|
||||
#define ESP_ERR_WIFI_NOT_STARTED (ESP_ERR_WIFI_BASE + 2) /*!< WiFi driver was not started by esp_wifi_start */
|
||||
#define ESP_ERR_WIFI_NOT_STOPPED (ESP_ERR_WIFI_BASE + 3) /*!< WiFi driver was not stopped by esp_wifi_stop */
|
||||
#define ESP_ERR_WIFI_IF (ESP_ERR_WIFI_BASE + 4) /*!< WiFi interface error */
|
||||
#define ESP_ERR_WIFI_MODE (ESP_ERR_WIFI_BASE + 5) /*!< WiFi mode error */
|
||||
#define ESP_ERR_WIFI_STATE (ESP_ERR_WIFI_BASE + 6) /*!< WiFi internal state error */
|
||||
#define ESP_ERR_WIFI_CONN (ESP_ERR_WIFI_BASE + 7) /*!< WiFi internal control block of station or soft-AP error */
|
||||
#define ESP_ERR_WIFI_NVS (ESP_ERR_WIFI_BASE + 8) /*!< WiFi internal NVS module error */
|
||||
#define ESP_ERR_WIFI_MAC (ESP_ERR_WIFI_BASE + 9) /*!< MAC address is invalid */
|
||||
#define ESP_ERR_WIFI_SSID (ESP_ERR_WIFI_BASE + 10) /*!< SSID is invalid */
|
||||
#define ESP_ERR_WIFI_PASSWORD (ESP_ERR_WIFI_BASE + 11) /*!< Password is invalid */
|
||||
#define ESP_ERR_WIFI_TIMEOUT (ESP_ERR_WIFI_BASE + 12) /*!< Timeout error */
|
||||
#define ESP_ERR_WIFI_WAKE_FAIL (ESP_ERR_WIFI_BASE + 13) /*!< WiFi is in sleep state(RF closed) and wakeup fail */
|
||||
#define ESP_ERR_WIFI_WOULD_BLOCK (ESP_ERR_WIFI_BASE + 14) /*!< The caller would block */
|
||||
#define ESP_ERR_WIFI_NOT_CONNECT (ESP_ERR_WIFI_BASE + 15) /*!< Station still in disconnect status */
|
||||
|
||||
#define ESP_WIFI_PARAM_USE_NVS 0
|
||||
|
||||
/**
|
||||
* @brief WiFi stack configuration parameters passed to esp_wifi_init call.
|
||||
*/
|
||||
typedef struct {
|
||||
system_event_handler_t event_handler; /**< WiFi event handler */
|
||||
wifi_osi_funcs_t* osi_funcs; /**< WiFi OS functions */
|
||||
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 magic; /**< WiFi init magic number, it should be the last field */
|
||||
} wifi_init_config_t;
|
||||
|
||||
#define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F
|
||||
|
||||
extern wifi_osi_funcs_t s_wifi_osi_funcs;
|
||||
#define WIFI_INIT_CONFIG_DEFAULT() { \
|
||||
.event_handler = &esp_event_send, \
|
||||
.osi_funcs = &s_wifi_osi_funcs, \
|
||||
.static_rx_buf_num = 5,\
|
||||
.dynamic_rx_buf_num = 0,\
|
||||
.tx_buf_type = 0,\
|
||||
.static_tx_buf_num = 6,\
|
||||
.dynamic_tx_buf_num = 0,\
|
||||
.csi_enable = 0,\
|
||||
.ampdu_rx_enable = 0,\
|
||||
.ampdu_tx_enable = 0,\
|
||||
.nvs_enable = 1,\
|
||||
.nano_enable = 0,\
|
||||
.tx_ba_win = 0,\
|
||||
.rx_ba_win = 0,\
|
||||
.magic = WIFI_INIT_CONFIG_MAGIC\
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Init WiFi
|
||||
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
|
||||
* WiFi NVS structure etc, this WiFi also start WiFi task
|
||||
*
|
||||
* @attention 1. This API must be called before all other WiFi API can be called
|
||||
* @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can
|
||||
* guarantee all the fields got correct value when more fields are added into wifi_init_config_t
|
||||
* in future release. If you want to set your owner initial values, overwrite the default values
|
||||
* which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of
|
||||
* wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!
|
||||
*
|
||||
* @param config pointer to WiFi init configuration structure; can point to a temporary variable.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_NO_MEM: out of memory
|
||||
* - others: refer to error code esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_init(const wifi_init_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Deinit WiFi
|
||||
* Free all resource allocated in esp_wifi_init and stop WiFi task
|
||||
*
|
||||
* @attention 1. This API should be called if you want to remove WiFi driver from the system
|
||||
*
|
||||
* @return ESP_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Set the WiFi operating mode
|
||||
*
|
||||
* Set the WiFi operating mode as station, soft-AP or station+soft-AP,
|
||||
* The default mode is soft-AP mode.
|
||||
*
|
||||
* @param mode WiFi operating mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - others: refer to error code in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_set_mode(wifi_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Get current operating mode of WiFi
|
||||
*
|
||||
* @param[out] mode store current WiFi mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - 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_mode(wifi_mode_t *mode);
|
||||
|
||||
/**
|
||||
* @brief Start WiFi according to current configuration
|
||||
* If mode is WIFI_MODE_STA, it create station control block and start station
|
||||
* If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP
|
||||
* If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_NO_MEM: out of memory
|
||||
* - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
|
||||
* - ESP_FAIL: other WiFi internal errors
|
||||
*/
|
||||
esp_err_t esp_wifi_start(void);
|
||||
|
||||
/**
|
||||
* @brief Stop WiFi
|
||||
* If mode is WIFI_MODE_STA, it stop station and free station control block
|
||||
* If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block
|
||||
* If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Restore WiFi stack persistent settings to default values
|
||||
*
|
||||
* This function will reset settings made using the following APIs:
|
||||
* - esp_wifi_get_auto_connect,
|
||||
* - esp_wifi_set_protocol,
|
||||
* - esp_wifi_set_config related
|
||||
* - esp_wifi_set_mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_restore(void);
|
||||
|
||||
/**
|
||||
* @brief Connect the ESP8266 WiFi station to the AP.
|
||||
*
|
||||
* @attention 1. This API only impact WIFI_MODE_STA or WIFI_MODE_APSTA mode
|
||||
* @attention 2. If the ESP8266 is connected to an AP, call esp_wifi_disconnect to disconnect.
|
||||
*
|
||||
* @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
|
||||
* - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
|
||||
* - ESP_ERR_WIFI_SSID: SSID of AP which station connects is invalid
|
||||
*/
|
||||
esp_err_t esp_wifi_connect(void);
|
||||
|
||||
/**
|
||||
* @brief Disconnect the ESP8266 WiFi station from the AP.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi was not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
|
||||
* - ESP_FAIL: other WiFi internal errors
|
||||
*/
|
||||
esp_err_t esp_wifi_disconnect(void);
|
||||
|
||||
/**
|
||||
* @brief Currently this API is just an stub API
|
||||
*
|
||||
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - others: fail
|
||||
*/
|
||||
esp_err_t esp_wifi_clear_fast_connect(void);
|
||||
|
||||
/**
|
||||
* @brief deauthenticate all stations or associated id equals to aid
|
||||
*
|
||||
* @param aid when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_MODE: WiFi mode is wrong
|
||||
*/
|
||||
esp_err_t esp_wifi_deauth_sta(uint16_t aid);
|
||||
|
||||
/**
|
||||
* @brief Scan all available APs.
|
||||
*
|
||||
* @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the
|
||||
* will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause
|
||||
* the memory to be freed once the scan is done
|
||||
* @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.
|
||||
* Values above 1500ms may cause station to disconnect from AP and are not recommended.
|
||||
*
|
||||
* @param config configuration of scanning
|
||||
* @param block if block is true, this API will block the caller until the scan is done, otherwise
|
||||
* it will return immediately
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout
|
||||
* - others: refer to error code in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block);
|
||||
|
||||
/**
|
||||
* @brief Stop the scan in process
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
|
||||
*/
|
||||
esp_err_t esp_wifi_scan_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Get number of APs found in last scan
|
||||
*
|
||||
* @param[out] number store number of APIs found in last scan
|
||||
*
|
||||
* @attention This API can only be called when the scan is completed, otherwise it may get wrong value.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);
|
||||
|
||||
/**
|
||||
* @brief Get AP list found in last scan
|
||||
*
|
||||
* @param[inout] number As input param, it stores max AP number ap_records can hold.
|
||||
* As output param, it receives the actual AP number this API returns.
|
||||
* @param ap_records wifi_ap_record_t array to hold the found APs
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_NO_MEM: out of memory
|
||||
*/
|
||||
esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get information of AP which the ESP8266 station is associated with
|
||||
*
|
||||
* @param ap_info the wifi_ap_record_t to hold AP information
|
||||
* sta can get the connected ap's phy mode info through the struct member
|
||||
* phy_11b,phy_11g,phy_11n,phy_lr in the wifi_ap_record_t struct.
|
||||
* For example, phy_11b = 1 imply that ap support 802.11b mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_CONN: The station interface don't initialized
|
||||
* - ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info);
|
||||
|
||||
/**
|
||||
* @brief Set current power save type
|
||||
*
|
||||
* @attention Default power save type is WIFI_PS_NONE.
|
||||
*
|
||||
* @param type power save type
|
||||
*
|
||||
* @return ESP_ERR_NOT_SUPPORTED: not supported yet
|
||||
*/
|
||||
esp_err_t esp_wifi_set_ps(wifi_ps_type_t type);
|
||||
|
||||
/**
|
||||
* @brief Get current power save type
|
||||
*
|
||||
* @attention Default power save type is WIFI_PS_NONE.
|
||||
*
|
||||
* @param[out] type: store current power save type
|
||||
*
|
||||
* @return ESP_ERR_NOT_SUPPORTED: not supported yet
|
||||
*/
|
||||
esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type);
|
||||
|
||||
/**
|
||||
* @brief Set protocol type of specified interface
|
||||
* The default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)
|
||||
*
|
||||
* @attention Currently we only support 802.11b or 802.11bg or 802.11bgn mode
|
||||
*
|
||||
* @param ifx interfaces
|
||||
* @param protocol_bitmap WiFi protocol bitmap
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - others: refer to error codes in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap);
|
||||
|
||||
/**
|
||||
* @brief Get the current protocol bitmap of the specified interface
|
||||
*
|
||||
* @param ifx interface
|
||||
* @param[out] protocol_bitmap store current WiFi protocol bitmap of interface ifx
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - others: refer to error codes in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap);
|
||||
|
||||
/**
|
||||
* @brief Set the bandwidth of ESP8266 specified interface
|
||||
*
|
||||
* @attention 1. API return false if try to configure an interface that is not enabled
|
||||
* @attention 2. WIFI_BW_HT40 is supported only when the interface support 11N
|
||||
*
|
||||
* @param ifx interface to be configured
|
||||
* @param bw bandwidth
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - others: refer to error codes in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw);
|
||||
|
||||
/**
|
||||
* @brief Get the bandwidth of ESP8266 specified interface
|
||||
*
|
||||
* @attention 1. API return false if try to get a interface that is not enable
|
||||
*
|
||||
* @param ifx interface to be configured
|
||||
* @param[out] bw store bandwidth of interface ifx
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
|
||||
|
||||
/**
|
||||
* @brief Set primary/secondary channel of ESP8266
|
||||
*
|
||||
* @attention 1. This is a special API for sniffer
|
||||
* @attention 2. This API should be called after esp_wifi_start() or esp_wifi_set_promiscuous()
|
||||
*
|
||||
* @param primary for HT20, primary is the channel number, for HT40, primary is the primary channel
|
||||
* @param second for HT20, second is ignored, for HT40, second is the second channel
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second);
|
||||
|
||||
/**
|
||||
* @brief Get the primary/secondary channel of ESP8266
|
||||
*
|
||||
* @attention 1. API return false if try to get a interface that is not enable
|
||||
*
|
||||
* @param primary store current primary channel
|
||||
* @param[out] second store current second channel
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - 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_channel(uint8_t *primary, wifi_second_chan_t *second);
|
||||
|
||||
/**
|
||||
* @brief configure country info
|
||||
*
|
||||
* @attention 1. The default country is {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}
|
||||
* @attention 2. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which
|
||||
* the station is connected is used. E.g. if the configured country info is {.cc="USA", .schan=1, .nchan=11}
|
||||
* and the country info of the AP to which the station is connected is {.cc="JP", .schan=1, .nchan=14}
|
||||
* then the country info that will be used is {.cc="JP", .schan=1, .nchan=14}. If the station disconnected
|
||||
* from the AP the country info is set back back to the country info of the station automatically,
|
||||
* {.cc="USA", .schan=1, .nchan=11} in the example.
|
||||
* @attention 3. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, always use the configured country info.
|
||||
* @attention 4. When the country info is changed because of configuration or because the station connects to a different
|
||||
* external AP, the country IE in probe response/beacon of the soft-AP is changed also.
|
||||
* @attention 5. The country configuration is not stored into flash
|
||||
* @attention 6. This API doesn't validate the per-country rules, it's up to the user to fill in all fields according to
|
||||
* local regulations.
|
||||
*
|
||||
* @param country the configured country info
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_set_country(const wifi_country_t *country);
|
||||
|
||||
/**
|
||||
* @brief get the current country info
|
||||
*
|
||||
* @param country country info
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - 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_country(wifi_country_t *country);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set MAC address of the ESP8266 WiFi station or the soft-AP interface.
|
||||
*
|
||||
* @attention 1. This API can only be called when the interface is disabled
|
||||
* @attention 2. ESP8266 soft-AP and station have different MAC addresses, do not set them to be the same.
|
||||
* @attention 3. The bit 0 of the first byte of ESP8266 MAC address can not be 1. For example, the MAC address
|
||||
* can set to be "1a:XX:XX:XX:XX:XX", but can not be "15:XX:XX:XX:XX:XX".
|
||||
*
|
||||
* @param ifx interface
|
||||
* @param mac the MAC address
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_MAC: invalid mac address
|
||||
* - ESP_ERR_WIFI_MODE: WiFi mode is wrong
|
||||
* - others: refer to error codes in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]);
|
||||
|
||||
/**
|
||||
* @brief Get mac of specified interface
|
||||
*
|
||||
* @param ifx interface
|
||||
* @param[out] mac store mac of the interface ifx
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
*/
|
||||
esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]);
|
||||
|
||||
/**
|
||||
* @brief The RX callback function in the promiscuous mode.
|
||||
* Each time a packet is received, the callback function will be called.
|
||||
*
|
||||
* @param buf Data received. Type of data in buffer (wifi_promiscuous_pkt_t or wifi_pkt_rx_ctrl_t) indicated by 'type' parameter.
|
||||
* @param type promiscuous packet type.
|
||||
*
|
||||
*/
|
||||
typedef void (* wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t type);
|
||||
/**
|
||||
* @brief Register the RX callback function in the promiscuous mode.
|
||||
*
|
||||
* Each time a packet is received, the registered callback function will be called.
|
||||
*
|
||||
* @param cb callback
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
|
||||
|
||||
/**
|
||||
* @brief Enable the promiscuous mode.
|
||||
*
|
||||
* @param en false - disable, true - enable
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_promiscuous(bool en);
|
||||
|
||||
/**
|
||||
* @brief Get the promiscuous mode.
|
||||
*
|
||||
* @param[out] en store the current status of promiscuous mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - 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_promiscuous(bool *en);
|
||||
|
||||
/**
|
||||
* @brief Enable the promiscuous mode packet type filter.
|
||||
*
|
||||
* @note The default filter is to filter all packets except WIFI_PKT_MISC
|
||||
*
|
||||
* @param filter the packet type 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_filter(const wifi_promiscuous_filter_t *filter);
|
||||
|
||||
/**
|
||||
* @brief Get the promiscuous filter.
|
||||
*
|
||||
* @param[out] filter store the current status of promiscuous filter
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - 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_promiscuous_filter(wifi_promiscuous_filter_t *filter);
|
||||
|
||||
/**
|
||||
* @brief Set the configuration of the ESP8266 STA or AP
|
||||
*
|
||||
* @attention 1. This API can be called only when specified interface is enabled, otherwise, API fail
|
||||
* @attention 2. For station configuration, bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.
|
||||
* @attention 3. ESP8266 is limited to only one channel, so when in the soft-AP+station mode, the soft-AP will adjust its channel automatically to be the same as
|
||||
* the channel of the ESP8266 station.
|
||||
*
|
||||
* @param interface interface
|
||||
* @param conf station or soft-AP configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_MODE: invalid mode
|
||||
* - ESP_ERR_WIFI_PASSWORD: invalid password
|
||||
* - ESP_ERR_WIFI_NVS: WiFi internal NVS error
|
||||
* - others: refer to the erro code in esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf);
|
||||
|
||||
/**
|
||||
* @brief Get configuration of specified interface
|
||||
*
|
||||
* @param interface interface
|
||||
* @param[out] conf station or soft-AP configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
*/
|
||||
esp_err_t esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf);
|
||||
|
||||
/**
|
||||
* @brief Get STAs associated with soft-AP
|
||||
*
|
||||
* @attention SSC only API
|
||||
*
|
||||
* @param[out] sta station list
|
||||
* ap can get the connected sta's phy mode info through the struct member
|
||||
* phy_11b,phy_11g,phy_11n,phy_lr in the wifi_sta_info_t struct.
|
||||
* For example, phy_11b = 1 imply that sta support 802.11b mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_MODE: WiFi mode is wrong
|
||||
* - ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid
|
||||
*/
|
||||
esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the WiFi API configuration storage type
|
||||
*
|
||||
* @attention 1. The default value is WIFI_STORAGE_FLASH
|
||||
*
|
||||
* @param storage : storage type
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
|
||||
|
||||
/**
|
||||
* @brief Set auto connect
|
||||
* The default value is true
|
||||
*
|
||||
* @param en : true - enable auto connect / false - disable auto connect
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - 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) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Get the auto connect flag
|
||||
*
|
||||
* @param[out] en store current auto connect configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - 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) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Set 802.11 Vendor-Specific Information Element
|
||||
*
|
||||
* @param enable If true, specified IE is enabled. If false, specified IE is removed.
|
||||
* @param type Information Element type. Determines the frame type to associate with the IE.
|
||||
* @param idx Index to set or clear. Each IE type can be associated with up to two elements (indices 0 & 1).
|
||||
* @param vnd_ie Pointer to vendor specific element data. First 6 bytes should be a header with fields matching vendor_ie_data_t.
|
||||
* If enable is false, this argument is ignored and can be NULL. Data does not need to remain valid after the function returns.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init()
|
||||
* - ESP_ERR_INVALID_ARG: Invalid argument, including if first byte of vnd_ie is not WIFI_VENDOR_IE_ELEMENT_ID (0xDD)
|
||||
* or second byte is an invalid length.
|
||||
* - ESP_ERR_NO_MEM: Out of memory
|
||||
*/
|
||||
esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, const void *vnd_ie);
|
||||
|
||||
/**
|
||||
* @brief Function signature for received Vendor-Specific Information Element callback.
|
||||
* @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback.
|
||||
* @param type Information element type, based on frame type received.
|
||||
* @param sa Source 802.11 address.
|
||||
* @param vnd_ie Pointer to the vendor specific element data received.
|
||||
* @param rssi Received signal strength indication.
|
||||
*/
|
||||
typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi);
|
||||
|
||||
/**
|
||||
* @brief Register Vendor-Specific Information Element monitoring callback.
|
||||
*
|
||||
* @param cb Callback function
|
||||
* @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_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Set maximum WiFi transmiting power
|
||||
*
|
||||
* @attention WiFi transmiting power is divided to six levels in phy init data.
|
||||
* Level0 represents highest transmiting power and level5 represents lowest
|
||||
* transmiting power. Packets of different rates are transmitted in
|
||||
* different powers according to the configuration in phy init data.
|
||||
* This API only sets maximum WiFi transmiting power. If this API is called,
|
||||
* the transmiting power of every packet will be less than or equal to the
|
||||
* value set by this API. If this API is not called, the value of maximum
|
||||
* transmitting power set in phy_init_data.bin or menuconfig (depend on
|
||||
* whether to use phy init data in partition or not) will be used. Default
|
||||
* value is level0. Values passed in power are mapped to transmit power
|
||||
* levels as follows:
|
||||
* - [78, 127]: level0
|
||||
* - [76, 77]: level1
|
||||
* - [74, 75]: level2
|
||||
* - [68, 73]: level3
|
||||
* - [60, 67]: level4
|
||||
* - [52, 59]: level5
|
||||
* - [44, 51]: level5 - 2dBm
|
||||
* - [34, 43]: level5 - 4.5dBm
|
||||
* - [28, 33]: level5 - 6dBm
|
||||
* - [20, 27]: level5 - 8dBm
|
||||
* - [8, 19]: level5 - 11dBm
|
||||
* - [-128, 7]: level5 - 14dBm
|
||||
*
|
||||
* @param power Maximum WiFi transmiting power.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
esp_err_t esp_wifi_set_max_tx_power(int8_t power);
|
||||
|
||||
/**
|
||||
* @brief Get maximum WiFi transmiting power
|
||||
*
|
||||
* @attention This API gets maximum WiFi transmiting power. Values got
|
||||
* from power are mapped to transmit power levels as follows:
|
||||
* - 78: 19.5dBm
|
||||
* - 76: 19dBm
|
||||
* - 74: 18.5dBm
|
||||
* - 68: 17dBm
|
||||
* - 60: 15dBm
|
||||
* - 52: 13dBm
|
||||
* - 44: 11dBm
|
||||
* - 34: 8.5dBm
|
||||
* - 28: 7dBm
|
||||
* - 20: 5dBm
|
||||
* - 8: 2dBm
|
||||
* - -4: -1dBm
|
||||
*
|
||||
* @param power Maximum WiFi transmiting power.
|
||||
*
|
||||
* @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
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_max_tx_power(int8_t *power);
|
||||
|
||||
/**
|
||||
* @brief Set mask to enable or disable some WiFi events
|
||||
*
|
||||
* @attention 1. Mask can be created by logical OR of various WIFI_EVENT_MASK_ constants.
|
||||
* Events which have corresponding bit set in the mask will not be delivered to the system event handler.
|
||||
* @attention 2. Default WiFi event mask is WIFI_EVENT_MASK_AP_PROBEREQRECVED.
|
||||
* @attention 3. There may be lots of stations sending probe request data around.
|
||||
* Don't unmask this event unless you need to receive probe request data.
|
||||
*
|
||||
* @param mask WiFi event mask.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_event_mask(uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Get mask of WiFi events
|
||||
*
|
||||
* @param mask WiFi event mask.
|
||||
*
|
||||
* @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_event_mask(uint32_t *mask);
|
||||
|
||||
/**
|
||||
* @brief Send user-define 802.11 packets.
|
||||
*
|
||||
* @attention 1. Packet has to be the whole 802.11 packet, does not include the FCS.
|
||||
* The length of the packet has to be longer than the minimum length
|
||||
* of the header of 802.11 packet which is 24 bytes, and less than 1400 bytes.
|
||||
* @attention 2. Duration area is invalid for user, it will be filled in SDK.
|
||||
* @attention 3. The rate of sending packet is same as the management packet which
|
||||
* is the same as the system rate of sending packets.
|
||||
* @attention 4. Only after the previous packet was sent, entered the sent callback,
|
||||
* the next packet is allowed to send. Otherwise, wifi_send_pkt_freedom
|
||||
* will return fail.
|
||||
*
|
||||
* @param uint8 *buf : pointer of packet
|
||||
* @param uint16 len : packet length
|
||||
* @param bool sys_seq : follow the system's 802.11 packets sequence number or not,
|
||||
* if it is true, the sequence number will be increased 1 every
|
||||
* time a packet sent.
|
||||
*
|
||||
* @return ESP_OK, succeed;
|
||||
* @return ESP_FAIL, fail.
|
||||
*/
|
||||
esp_err_t esp_wifi_send_pkt_freedom(uint8_t *buf, int32_t len, bool sys_seq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_WIFI_H__ */
|
6
cpu/esp8266/vendor/esp-idf/esp8266/source/Makefile
vendored
Normal file
6
cpu/esp8266/vendor/esp-idf/esp8266/source/Makefile
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
MODULE=esp_idf_esp8266
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/esp8266/source
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/util/include
|
29
cpu/esp8266/vendor/esp-idf/esp8266/source/chip_boot.c
vendored
Normal file
29
cpu/esp8266/vendor/esp-idf/esp8266/source/chip_boot.c
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifndef CONFIG_BOOTLOADER_INIT_SPI_FLASH
|
||||
#include "spi_flash.h"
|
||||
|
||||
/*
|
||||
* @brief initialize the chip
|
||||
*/
|
||||
void chip_boot(void)
|
||||
{
|
||||
extern void esp_spi_flash_init(uint32_t spi_speed, uint32_t spi_mode);
|
||||
|
||||
esp_spi_flash_init(CONFIG_SPI_FLASH_FREQ, CONFIG_SPI_FLASH_MODE);
|
||||
}
|
||||
#endif /* CONFIG_BOOTLOADER_INIT_SPI_FLASH */
|
333
cpu/esp8266/vendor/esp-idf/esp8266/source/esp_socket.c
vendored
Normal file
333
cpu/esp8266/vendor/esp-idf/esp8266/source/esp_socket.c
vendored
Normal file
@ -0,0 +1,333 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include "esp_socket.h"
|
||||
#include "net/sockio.h"
|
||||
|
||||
#define CRITICAL_DECLARE(t)
|
||||
#define CRITICAL_ENTER(t)
|
||||
#define CRITICAL_EXIT(t)
|
||||
|
||||
#ifndef ESP_SOCKET_MAX
|
||||
#define ESP_SOCKET_MAX 2
|
||||
#endif
|
||||
|
||||
#define SET_ERR(err) errno = err
|
||||
|
||||
#define CHECK_FD(s) \
|
||||
if (s >= ESP_SOCKET_MAX \
|
||||
|| !s_socket[s].info) { \
|
||||
SET_ERR(EINVAL); \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
#define CHECK_METHOD(s, io) \
|
||||
CHECK_FD(s) \
|
||||
if (!s_socket[s].method \
|
||||
|| !s_socket[s].method->io) { \
|
||||
SET_ERR(ESRCH); \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
#define SOCKET_IO_METHOD(s, io, ...) \
|
||||
s_socket[s].method->io(s_socket[s].index, ##__VA_ARGS__)
|
||||
|
||||
/*
|
||||
* socket event object
|
||||
*/
|
||||
typedef struct esp_socket_event {
|
||||
esp_aio_cb_t cb;
|
||||
void *arg;
|
||||
} esp_socket_event_t;
|
||||
|
||||
/*
|
||||
* socket object
|
||||
*/
|
||||
typedef struct esp_socket {
|
||||
esp_socket_info_t *info;
|
||||
|
||||
/*
|
||||
* lowlevel socket module index
|
||||
*/
|
||||
void *index;
|
||||
|
||||
/*
|
||||
* lowlevel socket module method
|
||||
*/
|
||||
const esp_socket_method_t *method;
|
||||
|
||||
esp_socket_event_t event[ESP_SOCKET_MAX_EVENT];
|
||||
} esp_socket_t;
|
||||
|
||||
static esp_socket_t s_socket[ESP_SOCKET_MAX];
|
||||
|
||||
static inline int event_is_used(int s, int e)
|
||||
{
|
||||
return s_socket[s].event[e].cb != NULL;
|
||||
}
|
||||
|
||||
static inline int alloc_event(int s, int e)
|
||||
{
|
||||
CRITICAL_DECLARE(t);
|
||||
|
||||
if (e >= ESP_SOCKET_MAX_EVENT)
|
||||
return -1;
|
||||
|
||||
CRITICAL_ENTER(t);
|
||||
if (event_is_used(s, e)) {
|
||||
e = ESP_SOCKET_MAX_EVENT;
|
||||
}
|
||||
CRITICAL_EXIT(t);
|
||||
|
||||
return e < ESP_SOCKET_MAX_EVENT ? e : -1;
|
||||
}
|
||||
|
||||
static inline void free_event(int s, int e)
|
||||
{
|
||||
s_socket[s].event[e].cb = NULL;
|
||||
}
|
||||
|
||||
static inline int alloc_socket(void)
|
||||
{
|
||||
int s;
|
||||
CRITICAL_DECLARE(t);
|
||||
|
||||
CRITICAL_ENTER(t);
|
||||
for (s = 0; s < ESP_SOCKET_MAX; s++) {
|
||||
if (s_socket[s].info == NULL) {
|
||||
s_socket[s].info = (void *)1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CRITICAL_EXIT(t);
|
||||
|
||||
return s < ESP_SOCKET_MAX ? s : -1;
|
||||
}
|
||||
|
||||
static inline void free_socket(int s)
|
||||
{
|
||||
int e;
|
||||
|
||||
s_socket[s].info = NULL;
|
||||
for (e = 0; e < ESP_SOCKET_MAX_EVENT; e++) {
|
||||
free_event(s, e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief create a socket file description
|
||||
*/
|
||||
int esp_socket(int domain, int type, int protocol)
|
||||
{
|
||||
int s;
|
||||
|
||||
s = alloc_socket();
|
||||
if (s < 0) {
|
||||
SET_ERR(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_socket[s].info = malloc(sizeof(esp_socket_info_t));
|
||||
if (!s_socket[s].info) {
|
||||
free_socket(s);
|
||||
SET_ERR(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_socket[s].info->domain = domain;
|
||||
s_socket[s].info->type = type;
|
||||
s_socket[s].info->protocol = protocol;
|
||||
|
||||
s_socket[s].index = NULL;
|
||||
s_socket[s].method = NULL;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief send a block of data asynchronously and receive result by callback function
|
||||
*/
|
||||
int esp_aio_sendto(esp_aio_t *aio, const struct sockaddr_ll *to, socklen_t len)
|
||||
{
|
||||
int s = aio->fd;
|
||||
|
||||
CHECK_METHOD(s, aio_sendto);
|
||||
|
||||
return SOCKET_IO_METHOD(s, aio_sendto, aio, to, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief register a event and its callback function to target of file description
|
||||
*/
|
||||
int esp_aio_event(int fd, unsigned int event, esp_aio_cb_t cb, void *arg)
|
||||
{
|
||||
int e;
|
||||
int ret;
|
||||
int s = fd;
|
||||
|
||||
CHECK_METHOD(s, aio_event);
|
||||
|
||||
e = alloc_event(s, event);
|
||||
if (e < 0) {
|
||||
SET_ERR(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = SOCKET_IO_METHOD(s, aio_event, event, cb, arg);
|
||||
if (ret) {
|
||||
free_event(s, e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_socket[s].event[e].cb = cb;
|
||||
s_socket[s].event[e].arg = arg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief lowlevel socket module upload event and its data
|
||||
*/
|
||||
int esp_upload_event(void *index, esp_socket_info_t *info, unsigned int event, esp_aio_data_t *aio_data)
|
||||
{
|
||||
int ret;
|
||||
int s;
|
||||
|
||||
if (event >= ESP_SOCKET_MAX_EVENT)
|
||||
return -EINVAL;
|
||||
|
||||
for (s = 0; s < ESP_SOCKET_MAX; s++) {
|
||||
if (s_socket[s].index == index && event_is_used(s, event)) {
|
||||
esp_aio_t aio;
|
||||
|
||||
aio.fd = s;
|
||||
aio.cb = s_socket[s].event[event].cb;
|
||||
aio.arg = s_socket[s].event[event].arg;
|
||||
|
||||
aio.pbuf = aio_data->pbuf;
|
||||
aio.len = aio_data->len;
|
||||
aio.ret = aio_data->status;
|
||||
|
||||
ret = s_socket[s].event[event].cb(&aio);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief free buffer taken from event callback
|
||||
*/
|
||||
int esp_free_pbuf(int fd, void *pbuf)
|
||||
{
|
||||
int ret;
|
||||
int s = fd;
|
||||
|
||||
CHECK_METHOD(s, free_pbuf);
|
||||
|
||||
ret = SOCKET_IO_METHOD(s, free_pbuf, pbuf);
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief map real lowlevel socket object to virtual socket
|
||||
*/
|
||||
static int map_socket_ll(int fd, const char *name)
|
||||
{
|
||||
int s = fd;
|
||||
const esp_socket_method_t *p;
|
||||
extern const esp_socket_method_t __start_ksymatabesp_socket, __stop_ksymatabesp_socket;
|
||||
|
||||
for (p = &__start_ksymatabesp_socket; p != &__stop_ksymatabesp_socket; p++) {
|
||||
if (!strcmp(name, p->name))
|
||||
break;
|
||||
}
|
||||
if (p >= &__stop_ksymatabesp_socket) {
|
||||
SET_ERR(ENXIO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_socket[s].index = p->open(s_socket[s].info);
|
||||
if (!s_socket[s].index)
|
||||
return -1;
|
||||
s_socket[s].method = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief send requset command to target by file description and get the result synchronously
|
||||
*/
|
||||
int esp_ioctl(int fd, unsigned int cmd, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list va;
|
||||
int s = fd;
|
||||
|
||||
va_start(va, cmd);
|
||||
|
||||
switch(cmd) {
|
||||
#if SIOCGIFINDEX != SIOGIFINDEX
|
||||
case SIOGIFINDEX:
|
||||
#endif
|
||||
case SIOCGIFINDEX: {
|
||||
const char *name;
|
||||
|
||||
name = va_arg(va, const char *);
|
||||
ret = map_socket_ll(fd, name);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
int *arg = ((int *)&cmd) + 1;
|
||||
|
||||
CHECK_METHOD(s, ioctl);
|
||||
ret = SOCKET_IO_METHOD(s, ioctl, cmd, arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief close target of file description
|
||||
*/
|
||||
int esp_close(int fd)
|
||||
{
|
||||
int ret;
|
||||
int s = fd;
|
||||
|
||||
CHECK_METHOD(s, close);
|
||||
|
||||
ret = SOCKET_IO_METHOD(s, close);
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
free(s_socket[s].info);
|
||||
free_socket(s);
|
||||
|
||||
return 0;
|
||||
}
|
75
cpu/esp8266/vendor/esp-idf/esp8266/source/esp_wifi.c
vendored
Normal file
75
cpu/esp8266/vendor/esp-idf/esp8266/source/esp_wifi.c
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_libc.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "internal/esp_wifi_internal.h"
|
||||
#include "esp_socket.h"
|
||||
#include "net/sockio.h"
|
||||
#include "phy.h"
|
||||
|
||||
const size_t _g_esp_wifi_ppt_task_stk_size = CONFIG_WIFI_PPT_TASKSTACK_SIZE;
|
||||
|
||||
esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Init WiFi
|
||||
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
|
||||
* WiFi NVS structure etc, this WiFi also start WiFi task
|
||||
*
|
||||
* @attention 1. This API must be called before all other WiFi API can be called
|
||||
* @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can
|
||||
* guarantee all the fields got correct value when more fields are added into wifi_init_config_t
|
||||
* in future release. If you want to set your owner initial values, overwrite the default values
|
||||
* which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of
|
||||
* wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!
|
||||
*
|
||||
* @param config pointer to WiFi init configuration structure; can point to a temporary variable.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_NO_MEM: out of memory
|
||||
* - others: refer to error code esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
||||
{
|
||||
esp_event_set_default_wifi_handlers();
|
||||
return esp_wifi_init_internal(config);
|
||||
}
|
||||
|
||||
void esp_deep_sleep_set_rf_option(uint8_t option)
|
||||
{
|
||||
phy_afterwake_set_rfoption(option);
|
||||
}
|
||||
|
||||
size_t __attribute__((weak)) esp_wifi_scan_get_ap_num_max(void)
|
||||
{
|
||||
return CONFIG_SCAN_AP_MAX;
|
||||
}
|
||||
|
||||
bool IRAM_ATTR esp_wifi_try_rate_from_high(void) {
|
||||
#if CONFIG_WIFI_TX_RATE_SEQUENCE_FROM_HIGH
|
||||
int8_t rssi;
|
||||
rssi = esp_wifi_get_ap_rssi();
|
||||
wifi_mode_t mode;
|
||||
esp_wifi_get_mode( &mode );
|
||||
if (rssi < -26 && mode == WIFI_MODE_STA) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
473
cpu/esp8266/vendor/esp-idf/esp8266/source/esp_wifi_os_adapter.c
vendored
Normal file
473
cpu/esp8266/vendor/esp-idf/esp8266/source/esp_wifi_os_adapter.c
vendored
Normal file
@ -0,0 +1,473 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_libc.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_wifi_os_adapter.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
#include "esp_log.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "xtensa/xtensa_api.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "nvs.h"
|
||||
|
||||
#if defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL) || defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NANO)
|
||||
#include "esp_newlib.h"
|
||||
#endif
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
|
||||
extern void vPortYield(void);
|
||||
extern void vPortYieldFromInt(void);
|
||||
#define portYIELD vPortYield
|
||||
void thread_yield_higher(void);
|
||||
|
||||
#endif /* RIOT_VERSION */
|
||||
|
||||
static void *task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio)
|
||||
{
|
||||
portBASE_TYPE ret;
|
||||
xTaskHandle handle;
|
||||
ret = xTaskCreate(task_func, name, stack_depth, param, prio, &handle);
|
||||
|
||||
return ret == pdPASS ? handle : NULL;
|
||||
}
|
||||
|
||||
static void task_delete_wrapper(void *task_handle)
|
||||
{
|
||||
vTaskDelete(task_handle);
|
||||
}
|
||||
|
||||
static void task_yield_wrapper(void)
|
||||
{
|
||||
#ifdef RIOT_VERSION
|
||||
thread_yield_higher();
|
||||
#else
|
||||
portYIELD();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void task_yield_from_isr_wrapper(void)
|
||||
{
|
||||
#ifdef RIOT_VERSION
|
||||
thread_yield_higher();
|
||||
#else
|
||||
portYIELD();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void task_delay_wrapper(uint32_t tick)
|
||||
{
|
||||
vTaskDelay(tick);
|
||||
}
|
||||
|
||||
static void* task_get_current_task_wrapper(void)
|
||||
{
|
||||
return (void *)xTaskGetCurrentTaskHandle();
|
||||
}
|
||||
|
||||
static uint32_t task_get_max_priority_wrapper(void)
|
||||
{
|
||||
return (uint32_t)(configMAX_PRIORITIES-1);
|
||||
}
|
||||
|
||||
static uint32_t task_ms_to_tick_wrapper(uint32_t ms)
|
||||
{
|
||||
return (uint32_t)(ms / portTICK_RATE_MS);
|
||||
}
|
||||
|
||||
static void task_suspend_all_wrapper(void)
|
||||
{
|
||||
#ifndef RIOT_VERSION
|
||||
/* there is no equivalent in RIOT */
|
||||
vTaskSuspendAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void task_resume_all_wrapper(void)
|
||||
{
|
||||
#ifndef RIOT_VERSION
|
||||
/* there is no equivalent in RIOT */
|
||||
xTaskResumeAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void os_init_wrapper(void)
|
||||
{
|
||||
#ifdef RIOT_VERSION
|
||||
extern void esp_riot_init(void);
|
||||
esp_riot_init();
|
||||
#else
|
||||
#if defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL) || defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NANO)
|
||||
esp_newlib_init();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void os_start_wrapper(void)
|
||||
{
|
||||
#ifdef RIOT_VERSION
|
||||
extern void esp_riot_start(void);
|
||||
esp_riot_start();
|
||||
#else
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *semphr_create_wrapper(uint32_t max, uint32_t init)
|
||||
{
|
||||
return (void *)xSemaphoreCreateCounting(max, init);
|
||||
}
|
||||
|
||||
static void semphr_delete_wrapper(void *semphr)
|
||||
{
|
||||
vSemaphoreDelete(semphr);
|
||||
}
|
||||
|
||||
static bool semphr_take_from_isr_wrapper(void *semphr, int *hptw)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xSemaphoreTakeFromISR(semphr, (signed portBASE_TYPE *)hptw);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool semphr_give_from_isr_wrapper(void *semphr, int *hptw)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xSemaphoreGiveFromISR(semphr, (signed portBASE_TYPE *)hptw);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool semphr_take_wrapper(void *semphr, uint32_t block_time_tick)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
|
||||
ret = xSemaphoreTake(semphr, portMAX_DELAY);
|
||||
} else {
|
||||
ret = xSemaphoreTake(semphr, block_time_tick);
|
||||
}
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool semphr_give_wrapper(void *semphr)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xSemaphoreGive(semphr);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static void *mutex_create_wrapper(void)
|
||||
{
|
||||
return (void *)xSemaphoreCreateRecursiveMutex();
|
||||
}
|
||||
|
||||
static void mutex_delete_wrapper(void *mutex)
|
||||
{
|
||||
vSemaphoreDelete(mutex);
|
||||
}
|
||||
|
||||
static bool mutex_lock_wrapper(void *mutex)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool mutex_unlock_wrapper(void *mutex)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xSemaphoreGiveRecursive(mutex);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static void *queue_create_wrapper(uint32_t queue_len, uint32_t item_size)
|
||||
{
|
||||
return (void *)xQueueCreate(queue_len, item_size);
|
||||
}
|
||||
|
||||
static void queue_delete_wrapper(void *queue)
|
||||
{
|
||||
vQueueDelete(queue);
|
||||
}
|
||||
|
||||
static bool queue_send_wrapper(void *queue, void *item, uint32_t block_time_tick, uint32_t pos)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
BaseType_t os_pos;
|
||||
|
||||
if (pos == OSI_QUEUE_SEND_BACK)
|
||||
os_pos = queueSEND_TO_BACK;
|
||||
else if (pos == OSI_QUEUE_SEND_FRONT)
|
||||
os_pos = queueSEND_TO_FRONT;
|
||||
else
|
||||
os_pos = queueOVERWRITE;
|
||||
|
||||
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
|
||||
ret = xQueueGenericSend(queue, item, portMAX_DELAY, os_pos);
|
||||
} else {
|
||||
ret = xQueueGenericSend(queue, item, block_time_tick, os_pos);
|
||||
}
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool queue_send_from_isr_wrapper(void *queue, void *item, int *hptw)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xQueueSendFromISR(queue, item, (signed portBASE_TYPE *)hptw);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool queue_recv_wrapper(void *queue, void *item, uint32_t block_time_tick)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
|
||||
ret = xQueueReceive(queue, item, portMAX_DELAY);
|
||||
} else {
|
||||
ret = xQueueReceive(queue, item, block_time_tick);
|
||||
}
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static bool queue_recv_from_isr_wrapper(void *queue, void *item, int *hptw)
|
||||
{
|
||||
signed portBASE_TYPE ret;
|
||||
|
||||
ret = xQueueReceiveFromISR(queue, item, (signed portBASE_TYPE *)hptw);
|
||||
|
||||
return ret == pdPASS ? true : false;
|
||||
}
|
||||
|
||||
static uint32_t queue_msg_waiting_wrapper(void *queue)
|
||||
{
|
||||
return (uint32_t)uxQueueMessagesWaiting(queue);
|
||||
}
|
||||
|
||||
static uint32_t get_free_heap_size_wrapper(void)
|
||||
{
|
||||
return (uint32_t)esp_get_free_heap_size();
|
||||
}
|
||||
|
||||
static void *timer_create_wrapper(const char *name, uint32_t period_ticks, bool auto_load, void *arg, void (*cb)(void *timer))
|
||||
{
|
||||
#ifdef MODULE_ESP_WIFI_ANY
|
||||
return xTimerCreate(name, period_ticks, auto_load, arg, (tmrTIMER_CALLBACK)cb);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *timer_get_arg_wrapper(void *timer)
|
||||
{
|
||||
#ifdef MODULE_ESP_WIFI_ANY
|
||||
return pvTimerGetTimerID(timer);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool timer_reset_wrapper(void *timer, uint32_t ticks)
|
||||
{
|
||||
#ifdef MODULE_ESP_WIFI_ANY
|
||||
return xTimerReset(timer, ticks);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool timer_stop_wrapper(void *timer, uint32_t ticks)
|
||||
{
|
||||
#ifdef MODULE_ESP_WIFI_ANY
|
||||
return xTimerStop(timer, ticks);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool timer_delete_wrapper(void *timer, uint32_t ticks)
|
||||
{
|
||||
#ifdef MODULE_ESP_WIFI_ANY
|
||||
return xTimerDelete(timer, ticks);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *malloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t line)
|
||||
{
|
||||
uint32_t os_caps;
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
return _heap_caps_malloc(s, os_caps, file, line);
|
||||
}
|
||||
|
||||
static void *zalloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t line)
|
||||
{
|
||||
uint32_t os_caps;
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
return _heap_caps_zalloc(s, os_caps, file, line);
|
||||
}
|
||||
|
||||
static void *realloc_wrapper(void *ptr, uint32_t s, uint32_t cap, const char *file, size_t line)
|
||||
{
|
||||
uint32_t os_caps;
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
return _heap_caps_realloc(ptr, s, os_caps, file, line);
|
||||
}
|
||||
|
||||
static void *calloc_wrapper(uint32_t cnt, uint32_t s, uint32_t cap, const char *file, size_t line)
|
||||
{
|
||||
uint32_t os_caps;
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
return _heap_caps_calloc(cnt , s, os_caps, file, line);
|
||||
}
|
||||
|
||||
static void free_wrapper(void *ptr, const char *file, size_t line)
|
||||
{
|
||||
_heap_caps_free(ptr, file, line);
|
||||
}
|
||||
|
||||
static void srand_wrapper(uint32_t seed)
|
||||
{
|
||||
/* empty function */
|
||||
}
|
||||
|
||||
static int32_t rand_wrapper(void)
|
||||
{
|
||||
return (int32_t)esp_random();
|
||||
}
|
||||
|
||||
void *osi_task_top_sp(void)
|
||||
{
|
||||
extern volatile thread_t *sched_active_thread;
|
||||
return sched_active_thread ? sched_active_thread->sp : 0;
|
||||
}
|
||||
|
||||
const wifi_osi_funcs_t s_wifi_osi_funcs = {
|
||||
.version = ESP_WIFI_OS_ADAPTER_VERSION,
|
||||
|
||||
.task_create = task_create_wrapper,
|
||||
.task_delete = task_delete_wrapper,
|
||||
.task_yield = task_yield_wrapper,
|
||||
.task_yield_from_isr = task_yield_from_isr_wrapper,
|
||||
.task_delay = task_delay_wrapper,
|
||||
.task_get_current_task = task_get_current_task_wrapper,
|
||||
.task_get_max_priority = task_get_max_priority_wrapper,
|
||||
|
||||
.task_ms_to_tick = task_ms_to_tick_wrapper,
|
||||
|
||||
.task_suspend_all = task_suspend_all_wrapper,
|
||||
.task_resume_all = task_resume_all_wrapper,
|
||||
|
||||
.os_init = os_init_wrapper,
|
||||
.os_start = os_start_wrapper,
|
||||
|
||||
.semphr_create = semphr_create_wrapper,
|
||||
.semphr_delete = semphr_delete_wrapper,
|
||||
.semphr_take_from_isr = semphr_take_from_isr_wrapper,
|
||||
.semphr_give_from_isr = semphr_give_from_isr_wrapper,
|
||||
.semphr_take = semphr_take_wrapper,
|
||||
.semphr_give = semphr_give_wrapper,
|
||||
|
||||
.mutex_create = mutex_create_wrapper,
|
||||
.mutex_delete = mutex_delete_wrapper,
|
||||
.mutex_lock = mutex_lock_wrapper,
|
||||
.mutex_unlock = mutex_unlock_wrapper,
|
||||
|
||||
.queue_create = queue_create_wrapper,
|
||||
.queue_delete = queue_delete_wrapper,
|
||||
.queue_send = queue_send_wrapper,
|
||||
.queue_send_from_isr = queue_send_from_isr_wrapper,
|
||||
.queue_recv = queue_recv_wrapper,
|
||||
.queue_recv_from_isr = queue_recv_from_isr_wrapper,
|
||||
.queue_msg_waiting = queue_msg_waiting_wrapper,
|
||||
|
||||
.timer_create = timer_create_wrapper,
|
||||
.timer_get_arg = timer_get_arg_wrapper,
|
||||
.timer_reset = timer_reset_wrapper,
|
||||
.timer_stop = timer_stop_wrapper,
|
||||
.timer_delete = timer_delete_wrapper,
|
||||
|
||||
.malloc = malloc_wrapper,
|
||||
.zalloc = zalloc_wrapper,
|
||||
.realloc = realloc_wrapper,
|
||||
.calloc = calloc_wrapper,
|
||||
.free = free_wrapper,
|
||||
.get_free_heap_size = get_free_heap_size_wrapper,
|
||||
|
||||
.srand = srand_wrapper,
|
||||
.rand = rand_wrapper,
|
||||
|
||||
.nvs_set_i8 = nvs_set_i8,
|
||||
.nvs_get_i8 = nvs_get_i8,
|
||||
.nvs_set_u8 = nvs_set_u8,
|
||||
.nvs_get_u8 = nvs_get_u8,
|
||||
.nvs_set_u16 = nvs_set_u16,
|
||||
.nvs_get_u16 = nvs_get_u16,
|
||||
.nvs_open = nvs_open,
|
||||
.nvs_close = nvs_close,
|
||||
.nvs_commit = nvs_commit,
|
||||
.nvs_set_blob = nvs_set_blob,
|
||||
.nvs_get_blob = nvs_get_blob,
|
||||
.nvs_erase_key = nvs_erase_key,
|
||||
|
||||
.magic = ESP_WIFI_OS_ADAPTER_MAGIC,
|
||||
};
|
310
cpu/esp8266/vendor/esp-idf/esp8266/source/ets_printf.c
vendored
Normal file
310
cpu/esp8266/vendor/esp-idf/esp8266/source/ets_printf.c
vendored
Normal file
@ -0,0 +1,310 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "esp_attr.h"
|
||||
|
||||
#include "esp8266/eagle_soc.h"
|
||||
#include "esp8266/uart_register.h"
|
||||
#include "esp8266/rom_functions.h"
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
|
||||
/* RIOT has its own putchar function which writes to UART */
|
||||
extern int putchar(int c);
|
||||
#define uart_putc putchar
|
||||
|
||||
#else /* RIOT_VERSION */
|
||||
|
||||
#ifndef CONFIG_CONSOLE_UART_NONE
|
||||
static void uart_putc(int c)
|
||||
{
|
||||
while (1) {
|
||||
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_CONSOLE_UART_NUM)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
|
||||
|
||||
if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126)
|
||||
break;
|
||||
}
|
||||
|
||||
WRITE_PERI_REG(UART_FIFO(CONFIG_CONSOLE_UART_NUM) , c);
|
||||
}
|
||||
#else
|
||||
#define uart_putc(_c) { }
|
||||
#endif
|
||||
|
||||
#endif /* RIOT_VERSION */
|
||||
|
||||
int __attribute__ ((weak)) ets_putc(int c)
|
||||
{
|
||||
#ifdef CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF
|
||||
if (c == '\n')
|
||||
uart_putc('\r');
|
||||
#elif defined(CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR)
|
||||
if (c == '\n')
|
||||
c = '\r';
|
||||
#endif
|
||||
|
||||
uart_putc(c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_USING_NEW_ETS_VPRINTF) && !defined(BOOTLOADER_BUILD)
|
||||
|
||||
#define FILL_0 0x01
|
||||
#define FILL_LEFT 0x02
|
||||
#define POINTOR 0x04
|
||||
#define ALTERNATE 0x08
|
||||
#define OUPUT_INT 0x10
|
||||
#define START 0x20
|
||||
|
||||
#define VINT_STR_MAX 10
|
||||
|
||||
typedef union _val_cache {
|
||||
uint8_t val8;
|
||||
int32_t val32;
|
||||
uint32_t val32u;
|
||||
const char *valcp;
|
||||
} val_cache_t;
|
||||
|
||||
typedef struct _val_attr {
|
||||
int8_t type;
|
||||
uint8_t state;
|
||||
uint8_t fillbytes;
|
||||
uint8_t precision;
|
||||
|
||||
val_cache_t value;
|
||||
} val_attr_t;
|
||||
|
||||
#define isdigit(_c) ((_c <= '9') && (_c >= '0'))
|
||||
#define fill_num(_attr) ((attr)->fillbytes)
|
||||
#define isfill_0(_attr) (fill_num(_attr) && ((_attr)->state & FILL_0))
|
||||
#define isfill_left(_attr) (fill_num(_attr) && ((_attr)->state & FILL_LEFT))
|
||||
#define isstart(_attr) ((_attr)->state & START)
|
||||
|
||||
static inline void ets_printf_ch_mutlti(uint32_t c, uint32_t len)
|
||||
{
|
||||
while (len--)
|
||||
ets_putc(c);
|
||||
}
|
||||
|
||||
static inline void ets_printf_buf(const char *s, uint32_t len)
|
||||
{
|
||||
while (len--)
|
||||
ets_putc(*s++);
|
||||
}
|
||||
|
||||
static int ets_printf_str(const val_attr_t * const attr)
|
||||
{
|
||||
const char *s = attr->value.valcp;
|
||||
s = s == NULL ? "<null>" : s;
|
||||
|
||||
if (fill_num(attr)) {
|
||||
unsigned char left;
|
||||
unsigned char len;
|
||||
|
||||
while (*s != '\0')
|
||||
s++;
|
||||
len = s - attr->value.valcp;
|
||||
left = fill_num(attr) > len ? fill_num(attr) - len : 0;
|
||||
|
||||
if (!isfill_left(attr)) {
|
||||
ets_printf_ch_mutlti(' ', left);
|
||||
}
|
||||
|
||||
ets_printf_buf(attr->value.valcp, len);
|
||||
|
||||
if (isfill_left(attr)) {
|
||||
ets_printf_ch_mutlti(' ', left);
|
||||
}
|
||||
} else {
|
||||
while (*s != '\0')
|
||||
ets_putc(*s++);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ets_printf_int(val_attr_t * const attr, uint8_t hex)
|
||||
{
|
||||
char buf[VINT_STR_MAX];
|
||||
unsigned char offset = VINT_STR_MAX;
|
||||
|
||||
if (attr->value.val32u != 0) {
|
||||
for (; attr->value.val32u > 0; attr->value.val32u /= hex) {
|
||||
unsigned char c = attr->value.val32u % hex;
|
||||
if (c < 10)
|
||||
buf[--offset] = c + '0';
|
||||
else
|
||||
buf[--offset] = c + 'a' - 10;
|
||||
}
|
||||
} else
|
||||
buf[--offset] = '0';
|
||||
|
||||
if (fill_num(attr)) {
|
||||
char fill_data = isfill_0(attr) ? '0' : ' ';
|
||||
unsigned char len = fill_num(attr) - (VINT_STR_MAX - offset);
|
||||
unsigned char left = fill_num(attr) > (VINT_STR_MAX - offset) ? len : 0;
|
||||
|
||||
if (!isfill_left(attr)) {
|
||||
ets_printf_ch_mutlti(fill_data, left);
|
||||
}
|
||||
|
||||
ets_printf_buf(&buf[offset], VINT_STR_MAX - offset);
|
||||
|
||||
if (isfill_left(attr)) {
|
||||
ets_printf_ch_mutlti(fill_data, left);
|
||||
}
|
||||
} else {
|
||||
ets_printf_buf(&buf[offset], VINT_STR_MAX - offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ets_vprintf(const char *fmt, va_list va)
|
||||
{
|
||||
for (; ;) {
|
||||
const char *ps = fmt;
|
||||
val_attr_t attr;
|
||||
|
||||
while (*ps != '\0' && *ps != '%')
|
||||
ets_putc(*ps++);
|
||||
|
||||
if (*ps == '\0')
|
||||
break;
|
||||
|
||||
fmt = ps;
|
||||
|
||||
attr.state = 0;
|
||||
attr.type = -1;
|
||||
attr.fillbytes = 0;
|
||||
attr.precision = 0;
|
||||
|
||||
for (; ;) {
|
||||
switch (*++ps) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'c':
|
||||
case 's':
|
||||
case 'p':
|
||||
case '\0':
|
||||
attr.type = *ps++;
|
||||
break;
|
||||
case '#':
|
||||
attr.state |= ALTERNATE;
|
||||
ps++;
|
||||
break;
|
||||
case '0'...'9':
|
||||
if (!isstart(&attr) && *ps == '0') {
|
||||
attr.state |= FILL_0;
|
||||
} else {
|
||||
if (attr.state & POINTOR)
|
||||
attr.precision = attr.precision * 10 + *ps - '0';
|
||||
else
|
||||
attr.fillbytes = attr.fillbytes * 10 + *ps - '0';
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
attr.state |= POINTOR;
|
||||
break;
|
||||
case '-':
|
||||
attr.state |= FILL_LEFT;
|
||||
break;
|
||||
default:
|
||||
attr.type = -2;
|
||||
break;
|
||||
}
|
||||
|
||||
attr.state |= START;
|
||||
|
||||
if (attr.type != -1)
|
||||
break;
|
||||
}
|
||||
|
||||
switch (attr.type) {
|
||||
case 'c':
|
||||
attr.value.val8 = (char)va_arg(va, int);
|
||||
ets_putc(attr.value.val8);
|
||||
break;
|
||||
case 's':
|
||||
attr.value.valcp = va_arg(va, const char *);
|
||||
ets_printf_str(&attr);
|
||||
break;
|
||||
case 'i':
|
||||
case 'd':
|
||||
attr.value.val32 = va_arg(va, int);
|
||||
if (attr.value.val32 < 0) {
|
||||
ets_putc('-');
|
||||
attr.value.val32 = -attr.value.val32;
|
||||
}
|
||||
ets_printf_int(&attr, 10);
|
||||
break;
|
||||
case 'u':
|
||||
attr.value.val32u = va_arg(va, unsigned int);
|
||||
ets_printf_int(&attr, 10);
|
||||
break;
|
||||
case 'x':
|
||||
attr.value.val32u = va_arg(va, unsigned int);
|
||||
ets_printf_int(&attr, 16);
|
||||
break;
|
||||
case 'p':
|
||||
attr.value.valcp = va_arg(va, const char *);
|
||||
ets_printf_int(&attr, 16);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
fmt = ps;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* defined(CONFIG_USING_NEW_ETS_VPRINTF) && !defined(BOOTLOADER_BUILD) */
|
||||
|
||||
int ets_vprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
return ets_io_vprintf(ets_putc, fmt, ap);
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_USING_NEW_ETS_VPRINTF) && !defined(BOOTLOADER_BUILD) */
|
||||
|
||||
/**
|
||||
* Re-write ets_printf in SDK side, since ets_printf in ROM will use a global
|
||||
* variable which address is in heap region of SDK side. If use ets_printf in ROM,
|
||||
* this variable maybe re-write when heap alloc and modification.
|
||||
*
|
||||
* Using new "ets_vprintf" costs stack without alignment and accuracy:
|
||||
* just "fmt": 136 Bytes
|
||||
* "%s": 172 Bytes
|
||||
* "%p", "%d, "%i, "%u", "%x": 215 Bytes
|
||||
*/
|
||||
int ets_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = ets_vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
376
cpu/esp8266/vendor/esp-idf/esp8266/source/event_default_handlers.c
vendored
Normal file
376
cpu/esp8266/vendor/esp-idf/esp8266/source/event_default_handlers.c
vendored
Normal file
@ -0,0 +1,376 @@
|
||||
// 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.
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
#include "esp_common.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#ifndef RIOT_VERSION
|
||||
#include "tcpip_adapter.h"
|
||||
#endif
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char* TAG = "event";
|
||||
|
||||
#define WIFI_API_CALL_CHECK(info, api_call, ret) \
|
||||
do{\
|
||||
esp_err_t __err = (api_call);\
|
||||
if ((ret) != __err) {\
|
||||
ESP_LOGE(TAG, "%s %d %s ret=0x%X", __FUNCTION__, __LINE__, (info), __err);\
|
||||
return __err;\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
typedef esp_err_t (*system_event_handler_t)(system_event_t *e);
|
||||
|
||||
static esp_err_t system_event_ap_start_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_ap_stop_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_start_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_stop_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_connected_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_got_ip_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_lost_ip_default(system_event_t *event);
|
||||
|
||||
/* Default event handler functions
|
||||
|
||||
Any entry in this table which is disabled by config will have a NULL handler.
|
||||
*/
|
||||
static system_event_handler_t default_event_handlers[SYSTEM_EVENT_MAX] = { 0 };
|
||||
|
||||
static esp_err_t system_event_sta_got_ip_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
ESP_LOGI(TAG, "sta ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip),
|
||||
IP2STR(&event->event_info.got_ip.ip_info.netmask),
|
||||
IP2STR(&event->event_info.got_ip.ip_info.gw));
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t system_event_sta_lost_ip_default(system_event_t *event)
|
||||
{
|
||||
ESP_LOGI(TAG, "station ip lost");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
tcpip_adapter_ip_info_t ap_ip;
|
||||
uint8_t ap_mac[6];
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_AP, ap_mac), ESP_OK);
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_AP, ap_mac, &ap_ip);
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_ap_stop_handle_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_AP);
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_start_handle_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
tcpip_adapter_ip_info_t sta_ip;
|
||||
uint8_t sta_mac[6];
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_STA, sta_mac), ESP_OK);
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_STA, sta_mac, &sta_ip);
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_stop_handle_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_STA);
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
tcpip_adapter_dhcp_status_t status;
|
||||
|
||||
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
|
||||
tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &status);
|
||||
|
||||
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
|
||||
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
||||
tcpip_adapter_ip_info_t sta_ip;
|
||||
tcpip_adapter_ip_info_t sta_old_ip;
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
tcpip_adapter_get_old_ip_info(TCPIP_ADAPTER_IF_STA, &sta_old_ip);
|
||||
|
||||
if (!(ip4_addr_isany_val(sta_ip.ip) || ip4_addr_isany_val(sta_ip.netmask) || ip4_addr_isany_val(sta_ip.gw))) {
|
||||
system_event_t evt;
|
||||
|
||||
evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
|
||||
evt.event_info.got_ip.ip_changed = false;
|
||||
|
||||
if (memcmp(&sta_ip, &sta_old_ip, sizeof(sta_ip))) {
|
||||
evt.event_info.got_ip.ip_changed = true;
|
||||
}
|
||||
|
||||
memcpy(&evt.event_info.got_ip.ip_info, &sta_ip, sizeof(tcpip_adapter_ip_info_t));
|
||||
tcpip_adapter_set_old_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
|
||||
esp_event_send(&evt);
|
||||
ESP_LOGD(TAG, "static ip: ip changed=%d", evt.event_info.got_ip.ip_changed);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "invalid static ip");
|
||||
}
|
||||
}
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event)
|
||||
{
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
tcpip_adapter_down(TCPIP_ADAPTER_IF_STA);
|
||||
#else
|
||||
ESP_LOGI(TAG, "%s", __func__);
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_system_event_debug(system_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
ESP_LOGE(TAG, "event is null!");
|
||||
printf("event is null!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
switch (event->event_id) {
|
||||
case SYSTEM_EVENT_WIFI_READY: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_WIFI_READY");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_SCAN_DONE: {
|
||||
system_event_sta_scan_done_t *scan_done = &event->event_info.scan_done;
|
||||
(void)scan_done; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_SCAN_DONE, status:%d, number:%d", scan_done->status, scan_done->number);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_STOP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_CONNECTED: {
|
||||
system_event_sta_connected_t *connected = &event->event_info.connected;
|
||||
(void)connected; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_CONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", channel:%d, authmode:%d", \
|
||||
connected->ssid, connected->ssid_len, MAC2STR(connected->bssid), connected->channel, connected->authmode);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
||||
system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected;
|
||||
(void)disconnected; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", reason:%d", \
|
||||
disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
||||
system_event_sta_authmode_change_t *auth_change = &event->event_info.auth_change;
|
||||
(void)auth_change; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_AUTHMODE_CHNAGE, old_mode:%d, new_mode:%d", auth_change->old_mode, auth_change->new_mode);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_GOT_IP: {
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
system_event_sta_got_ip_t *got_ip = &event->event_info.got_ip;
|
||||
(void)got_ip; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_GOT_IP, ip:" IPSTR ", mask:" IPSTR ", gw:" IPSTR,
|
||||
IP2STR(&got_ip->ip_info.ip),
|
||||
IP2STR(&got_ip->ip_info.netmask),
|
||||
IP2STR(&got_ip->ip_info.gw));
|
||||
#else
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_GOT_IP");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_LOST_IP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_LOST_IP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_SUCCESS");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_FAILED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_FAILED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_TIMEOUT");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_PIN: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_PIN");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STOP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STACONNECTED: {
|
||||
system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected;
|
||||
(void)staconnected; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:" MACSTR ", aid:%d", \
|
||||
MAC2STR(staconnected->mac), staconnected->aid);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STADISCONNECTED: {
|
||||
system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected;
|
||||
(void)stadisconnected; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:" MACSTR ", aid:%d", \
|
||||
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;
|
||||
(void)ap_probereqrecved; /* to avoid compile error: unused variable */
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \
|
||||
ap_probereqrecved->rssi, \
|
||||
MAC2STR(ap_probereqrecved->mac));
|
||||
break;
|
||||
}
|
||||
#if ESP_EVENT_IPV6
|
||||
case SYSTEM_EVENT_GOT_IP6: {
|
||||
#ifndef RIOT_VERSION /* TODO implement */
|
||||
ip6_addr_t *addr = &event->event_info.got_ip6.ip6_info.ip;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STA_GOT_IP6 address %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
|
||||
IP6_ADDR_BLOCK1(addr),
|
||||
IP6_ADDR_BLOCK2(addr),
|
||||
IP6_ADDR_BLOCK3(addr),
|
||||
IP6_ADDR_BLOCK4(addr),
|
||||
IP6_ADDR_BLOCK5(addr),
|
||||
IP6_ADDR_BLOCK6(addr),
|
||||
IP6_ADDR_BLOCK7(addr),
|
||||
IP6_ADDR_BLOCK8(addr));
|
||||
#else
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STA_GOT_IP6 address ");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
default: {
|
||||
ESP_LOGW(TAG, "unexpected system event %d!", event->event_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_process_default(system_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
ESP_LOGE(TAG, "Error: event is null!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_system_event_debug(event);
|
||||
if ((event->event_id < SYSTEM_EVENT_MAX)) {
|
||||
if (default_event_handlers[event->event_id] != NULL) {
|
||||
ESP_LOGV(TAG, "enter default callback");
|
||||
default_event_handlers[event->event_id](event);
|
||||
ESP_LOGV(TAG, "exit default callback");
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "mismatch or invalid event, id=%d", event->event_id);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void esp_event_set_default_wifi_handlers(void)
|
||||
{
|
||||
default_event_handlers[SYSTEM_EVENT_STA_START] = system_event_sta_start_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_STOP] = system_event_sta_stop_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_CONNECTED] = system_event_sta_connected_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_DISCONNECTED] = system_event_sta_disconnected_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_GOT_IP] = system_event_sta_got_ip_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_LOST_IP] = system_event_sta_lost_ip_default;
|
||||
default_event_handlers[SYSTEM_EVENT_AP_START] = system_event_ap_start_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_AP_STOP] = system_event_ap_stop_handle_default;
|
||||
|
||||
//esp_register_shutdown_handler((shutdown_handler_t)esp_wifi_stop);
|
||||
}
|
112
cpu/esp8266/vendor/esp-idf/esp8266/source/event_loop.c
vendored
Normal file
112
cpu/esp8266/vendor/esp-idf/esp8266/source/event_loop.c
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_wifi_osi.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char* TAG = "event";
|
||||
static bool s_event_init_flag = false;
|
||||
static void *s_event_queue = NULL;
|
||||
static system_event_cb_t s_event_handler_cb = NULL;
|
||||
static void *s_event_ctx = NULL;
|
||||
|
||||
static esp_err_t esp_event_post_to_user(system_event_t *event)
|
||||
{
|
||||
if (s_event_handler_cb) {
|
||||
return (*s_event_handler_cb)(s_event_ctx, event);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void esp_event_loop_task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
system_event_t evt;
|
||||
if (wifi_queue_recv(s_event_queue, &evt, OSI_FUNCS_TIME_BLOCKING) == pdPASS) {
|
||||
esp_err_t ret = esp_event_process_default(&evt);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "default event handler failed!");
|
||||
}
|
||||
ret = esp_event_post_to_user(&evt);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "post event to user fail!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
system_event_cb_t old_cb = s_event_handler_cb;
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
return old_cb;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_send(system_event_t *event)
|
||||
{
|
||||
if (s_event_queue == NULL) {
|
||||
ESP_LOGE(TAG, "Event loop not initialized via esp_event_loop_init, but esp_event_send called");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
int ret = wifi_queue_send(s_event_queue, event, 0, OSI_QUEUE_SEND_BACK);
|
||||
if (ret != true) {
|
||||
if (event) {
|
||||
ESP_LOGE(TAG, "e=%d f", event->event_id);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "e null");
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
QueueHandle_t esp_event_loop_get_queue(void)
|
||||
{
|
||||
return s_event_queue;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
if (s_event_init_flag) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
s_event_queue = wifi_queue_create(32, sizeof(system_event_t));
|
||||
if(s_event_queue == NULL)
|
||||
return ESP_ERR_NO_MEM;
|
||||
#ifdef RIOT_VERSION
|
||||
if(wifi_task_create(esp_event_loop_task, "esp_events", EVENT_LOOP_STACKSIZE, NULL, wifi_task_get_max_priority() - 5) == NULL) {
|
||||
#else
|
||||
if(wifi_task_create(esp_event_loop_task, "esp_event_loop_task", EVENT_LOOP_STACKSIZE, NULL, wifi_task_get_max_priority() - 5) == NULL) {
|
||||
#endif
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
s_event_init_flag = true;
|
||||
return ESP_OK;
|
||||
}
|
336
cpu/esp8266/vendor/esp-idf/esp8266/source/phy_init.c
vendored
Normal file
336
cpu/esp8266/vendor/esp-idf/esp8266/source/phy_init.c
vendored
Normal file
@ -0,0 +1,336 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_phy_init.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "phy_init_data.h"
|
||||
#include "phy.h"
|
||||
|
||||
static const char *TAG = "phy_init";
|
||||
|
||||
static uint8_t phy_check_calibration_data(uint8_t *rf_cal_data)
|
||||
{
|
||||
#define CHECK_NUM 26
|
||||
#define CHIP_ID_L 24
|
||||
#define CHIP_ID_H 25
|
||||
|
||||
uint8_t i;
|
||||
uint32_t *cal_data_word = (uint32_t *)rf_cal_data;
|
||||
uint32_t check_sum = 0;
|
||||
|
||||
/* L: flag_1[79:76], version[59:56], mac_map[55:48], mac_l[47:24] */
|
||||
uint32_t chip_id_l = ((REG_READ(0x3FF00058) & 0xF000) << 16) |
|
||||
(REG_READ(0x3ff00054) & 0xFFFFFFF);
|
||||
/* H: mac_l[31:24], mac_h[119:96] */
|
||||
uint32_t chip_id_h = (REG_READ(0x3FF00050) & 0xFF000000) |
|
||||
(REG_READ(0x3ff0005C) & 0xFFFFFF);
|
||||
|
||||
cal_data_word[CHIP_ID_L] = chip_id_l;
|
||||
cal_data_word[CHIP_ID_H] = chip_id_h;
|
||||
|
||||
for (i = 0; i < CHECK_NUM; i++) {
|
||||
check_sum += cal_data_word[i];
|
||||
}
|
||||
|
||||
return (cal_data_word[CHECK_NUM] != ~check_sum);
|
||||
}
|
||||
|
||||
/* temporary put rx_gain_dc_table in memory */
|
||||
/* ToDo: use rx_gain_dc_table in nvs, need to modify internal libraries */
|
||||
uint32_t rx_gain_dc_table[125];
|
||||
|
||||
esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibration_mode_t mode,
|
||||
esp_phy_calibration_data_t *calibration_data, phy_rf_module_t module)
|
||||
{
|
||||
esp_err_t status = ESP_OK;
|
||||
uint8_t sta_mac[6];
|
||||
uint8_t *local_init_data = calloc(1, 256);
|
||||
#ifdef CONFIG_CONSOLE_UART_BAUDRATE
|
||||
const uint32_t uart_baudrate = CONFIG_CONSOLE_UART_BAUDRATE;
|
||||
#else
|
||||
const uint32_t uart_baudrate = 74880; // ROM default baudrate
|
||||
#endif
|
||||
|
||||
memcpy(local_init_data, init_data->params, 128);
|
||||
|
||||
extern uint32_t *phy_rx_gain_dc_table;
|
||||
phy_rx_gain_dc_table = calibration_data->rx_gain_dc_table;
|
||||
uint8_t cal_data_check = phy_check_calibration_data(calibration_data->rf_cal_data) ||
|
||||
phy_check_data_table(phy_rx_gain_dc_table, 125, 1);
|
||||
|
||||
phy_afterwake_set_rfoption(1);
|
||||
|
||||
if (!cal_data_check) {
|
||||
write_data_to_rtc(calibration_data->rf_cal_data);
|
||||
}
|
||||
|
||||
esp_efuse_mac_get_default(sta_mac);
|
||||
chip_init(local_init_data, sta_mac, uart_baudrate);
|
||||
get_data_from_rtc((uint8_t *)calibration_data);
|
||||
|
||||
memcpy(rx_gain_dc_table, calibration_data->rx_gain_dc_table, 4 * 125);
|
||||
phy_rx_gain_dc_table = rx_gain_dc_table;
|
||||
|
||||
free(local_init_data);
|
||||
|
||||
if (cal_data_check == ESP_CAL_DATA_CHECK_FAIL) {
|
||||
#ifdef CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE
|
||||
ESP_LOGW(TAG, "saving new calibration data because of checksum failure, mode(%d)", mode);
|
||||
if (mode != PHY_RF_CAL_FULL) {
|
||||
esp_phy_store_cal_data_to_nvs(calibration_data);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
esp_err_t esp_phy_rf_deinit(phy_rf_module_t module)
|
||||
{
|
||||
esp_err_t status = ESP_OK;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// PHY init data handling functions
|
||||
#if CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
|
||||
#include "esp_partition.h"
|
||||
|
||||
const esp_phy_init_data_t *esp_phy_get_init_data(void)
|
||||
{
|
||||
const esp_partition_t *partition = esp_partition_find_first(
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL);
|
||||
|
||||
if (partition == NULL) {
|
||||
ESP_LOGE(TAG, "PHY data partition not found");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "loading PHY init data from partition at offset 0x%x", partition->address);
|
||||
size_t init_data_store_length = sizeof(phy_init_magic_pre) +
|
||||
sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post);
|
||||
uint8_t *init_data_store = (uint8_t *) malloc(init_data_store_length);
|
||||
|
||||
if (init_data_store == NULL) {
|
||||
ESP_LOGE(TAG, "failed to allocate memory for PHY init data");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "failed to read PHY data partition (0x%x)", err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 ||
|
||||
memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
|
||||
PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) {
|
||||
ESP_LOGE(TAG, "failed to validate PHY data partition");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "PHY data partition validated");
|
||||
return (const esp_phy_init_data_t *)(init_data_store + sizeof(phy_init_magic_pre));
|
||||
}
|
||||
|
||||
void esp_phy_release_init_data(const esp_phy_init_data_t *init_data)
|
||||
{
|
||||
free((uint8_t *) init_data - sizeof(phy_init_magic_pre));
|
||||
}
|
||||
|
||||
#else // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
|
||||
|
||||
// phy_init_data.h will declare static 'phy_init_data' variable initialized with default init data
|
||||
|
||||
const esp_phy_init_data_t *esp_phy_get_init_data(void)
|
||||
{
|
||||
ESP_LOGD(TAG, "loading PHY init data from application binary");
|
||||
return &phy_init_data;
|
||||
}
|
||||
|
||||
void esp_phy_release_init_data(const esp_phy_init_data_t *init_data)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
#endif // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
|
||||
|
||||
|
||||
// PHY calibration data handling functions
|
||||
static const char *PHY_NAMESPACE = "phy";
|
||||
static const char *PHY_CAL_DATA_KEY = "cal_data";
|
||||
static const char *PHY_RX_GAIN_DC_TABLE_KEY = "dc_table";
|
||||
|
||||
static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
|
||||
esp_phy_calibration_data_t *out_cal_data);
|
||||
|
||||
static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
|
||||
const esp_phy_calibration_data_t *cal_data);
|
||||
|
||||
esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t *out_cal_data)
|
||||
{
|
||||
nvs_handle handle;
|
||||
esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READONLY, &handle);
|
||||
|
||||
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
|
||||
ESP_LOGE(TAG, "%s: NVS has not been initialized. "
|
||||
"Call nvs_flash_init before starting WiFi/BT.", __func__);
|
||||
} else if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = load_cal_data_from_nvs_handle(handle, out_cal_data);
|
||||
nvs_close(handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t *cal_data)
|
||||
{
|
||||
nvs_handle handle;
|
||||
esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READWRITE, &handle);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
|
||||
return err;
|
||||
} else {
|
||||
err = store_cal_data_to_nvs_handle(handle, cal_data);
|
||||
nvs_close(handle);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
|
||||
esp_phy_calibration_data_t *out_cal_data)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
size_t length = sizeof(out_cal_data->rf_cal_data);
|
||||
|
||||
err = nvs_get_blob(handle, PHY_CAL_DATA_KEY, out_cal_data->rf_cal_data, &length);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: failed to get cal_data(0x%x)", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (length != sizeof(out_cal_data->rf_cal_data)) {
|
||||
ESP_LOGD(TAG, "%s: invalid length of cal_data (%d)", __func__, length);
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
length = sizeof(out_cal_data->rx_gain_dc_table);
|
||||
err = nvs_get_blob(handle, PHY_RX_GAIN_DC_TABLE_KEY, out_cal_data->rx_gain_dc_table, &length);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: failed to get rx_gain_dc_table(0x%x)", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (length != sizeof(out_cal_data->rx_gain_dc_table)) {
|
||||
ESP_LOGD(TAG, "%s: invalid length of rx_gain_dc_table (%d)", __func__, length);
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
|
||||
const esp_phy_calibration_data_t *cal_data)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data->rf_cal_data, sizeof(cal_data->rf_cal_data));
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: store calibration data failed(0x%x)\n", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_set_blob(handle, PHY_RX_GAIN_DC_TABLE_KEY, cal_data->rx_gain_dc_table, sizeof(cal_data->rx_gain_dc_table));
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: store rx gain dc table failed(0x%x)\n", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_commit(handle);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: store calibration nvs commit failed(0x%x)\n", __func__, err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void esp_phy_load_cal_and_init(phy_rf_module_t module)
|
||||
{
|
||||
esp_phy_calibration_data_t *cal_data =
|
||||
(esp_phy_calibration_data_t *) calloc(sizeof(esp_phy_calibration_data_t), 1);
|
||||
|
||||
if (cal_data == NULL) {
|
||||
ESP_LOGE(TAG, "failed to allocate memory for RF calibration data");
|
||||
abort();
|
||||
}
|
||||
|
||||
const esp_phy_init_data_t *init_data = esp_phy_get_init_data();
|
||||
|
||||
if (init_data == NULL) {
|
||||
ESP_LOGE(TAG, "failed to obtain PHY init data");
|
||||
abort();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE
|
||||
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
|
||||
|
||||
// if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
|
||||
// calibration_mode = PHY_RF_CAL_NONE;
|
||||
// }
|
||||
|
||||
esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "failed to load RF calibration data (0x%x), falling back to full calibration", err);
|
||||
calibration_mode = PHY_RF_CAL_FULL;
|
||||
}
|
||||
|
||||
esp_phy_rf_init(init_data, calibration_mode, cal_data, module);
|
||||
|
||||
if (calibration_mode != PHY_RF_CAL_NONE && err != ESP_OK) {
|
||||
err = esp_phy_store_cal_data_to_nvs(cal_data);
|
||||
} else {
|
||||
err = ESP_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
esp_phy_rf_init(init_data, PHY_RF_CAL_FULL, cal_data, module);
|
||||
#endif
|
||||
|
||||
esp_phy_release_init_data(init_data);
|
||||
|
||||
free(cal_data); // PHY maintains a copy of calibration data, so we can free this
|
||||
}
|
145
cpu/esp8266/vendor/esp-idf/esp8266/source/reset_reason.c
vendored
Normal file
145
cpu/esp8266/vendor/esp-idf/esp8266/source/reset_reason.c
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include <string.h>
|
||||
#include "esp_system.h"
|
||||
#include "internal/esp_system_internal.h"
|
||||
#include "esp8266/rtc_register.h"
|
||||
#include "esp8266/rom_functions.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_libc.h"
|
||||
|
||||
#if CONFIG_RESET_REASON
|
||||
|
||||
#define RTC_RESET_SW_CAUSE_REG RTC_STORE0
|
||||
#define RTC_RESET_HW_CAUSE_REG RTC_STATE1
|
||||
#define RTC_WAKEUP_HW_CAUSE_REG RTC_STATE2
|
||||
|
||||
#define RTC_RESET_HW_CAUSE_LSB 0
|
||||
#define RTC_RESET_HW_CAUSE_MSB 3
|
||||
|
||||
#define RTC_WAKEUP_HW_CAUSE_LSB 8
|
||||
#define RTC_WAKEUP_HW_CAUSE_MSB 13
|
||||
|
||||
static const char *TAG = "reset_reason";
|
||||
static uint32_t s_reset_reason;
|
||||
|
||||
static inline void esp_reset_reason_clear_hint()
|
||||
{
|
||||
rtc_sys_info.hint = 0;
|
||||
}
|
||||
|
||||
static inline uint32_t esp_reset_reason_get_hint(uint32_t hw_reset)
|
||||
{
|
||||
if (hw_reset == POWERON_RESET && rtc_sys_info.hint != ESP_RST_SW) {
|
||||
uint32_t *p = (uint32_t *)&rtc_sys_info;
|
||||
|
||||
for (int i = 0; i < RTC_SYS_RAM_SIZE / sizeof(uint32_t); i++)
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
return rtc_sys_info.hint;
|
||||
}
|
||||
|
||||
static inline uint32_t esp_rtc_get_reset_reason(void)
|
||||
{
|
||||
return GET_PERI_REG_BITS(RTC_RESET_HW_CAUSE_REG, RTC_RESET_HW_CAUSE_MSB, RTC_RESET_HW_CAUSE_LSB);
|
||||
}
|
||||
|
||||
#if CONFIG_RESET_REASON_CHECK_WAKEUP
|
||||
static inline uint32_t esp_rtc_get_wakeup_reason(void)
|
||||
{
|
||||
return GET_PERI_REG_BITS(RTC_WAKEUP_HW_CAUSE_REG, RTC_WAKEUP_HW_CAUSE_MSB, RTC_WAKEUP_HW_CAUSE_LSB);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint32_t get_reset_reason(uint32_t rtc_reset_reason, uint32_t reset_reason_hint)
|
||||
{
|
||||
switch (rtc_reset_reason) {
|
||||
case POWERON_RESET:
|
||||
if (reset_reason_hint == ESP_RST_SW)
|
||||
return reset_reason_hint;
|
||||
return ESP_RST_POWERON;
|
||||
case EXT_RESET:
|
||||
if (reset_reason_hint == ESP_RST_DEEPSLEEP) {
|
||||
return reset_reason_hint;
|
||||
}
|
||||
return ESP_RST_EXT;
|
||||
case SW_RESET:
|
||||
if (reset_reason_hint == ESP_RST_PANIC ||
|
||||
reset_reason_hint == ESP_RST_BROWNOUT ||
|
||||
reset_reason_hint == ESP_RST_TASK_WDT) {
|
||||
return reset_reason_hint;
|
||||
}
|
||||
return ESP_RST_SW;
|
||||
case DEEPSLEEP_RESET:
|
||||
return ESP_RST_DEEPSLEEP;
|
||||
case OWDT_RESET:
|
||||
return ESP_RST_WDT;
|
||||
case SDIO_RESET:
|
||||
return ESP_RST_SDIO;
|
||||
default:
|
||||
return ESP_RST_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Internal function to get SoC reset reason at system initialization
|
||||
*/
|
||||
void esp_reset_reason_init(void)
|
||||
{
|
||||
const uint32_t hw_reset = esp_rtc_get_reset_reason();
|
||||
#if CONFIG_RESET_REASON_CHECK_WAKEUP
|
||||
const uint32_t hw_wakeup = esp_rtc_get_wakeup_reason();
|
||||
#else
|
||||
const uint32_t hw_wakeup = 0;
|
||||
#endif
|
||||
const uint32_t hint = esp_reset_reason_get_hint(hw_reset);
|
||||
|
||||
s_reset_reason = get_reset_reason(hw_reset, hint);
|
||||
if (hint != ESP_RST_UNKNOWN) {
|
||||
esp_reset_reason_clear_hint();
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "RTC reset %u wakeup %u store %u, reason is %u", hw_reset, hw_wakeup, hint, s_reset_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Internal function to set reset reason hint
|
||||
*/
|
||||
void esp_reset_reason_set_hint(esp_reset_reason_t hint)
|
||||
{
|
||||
rtc_sys_info.hint = hint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get reason of last reset
|
||||
*/
|
||||
esp_reset_reason_t esp_reset_reason(void)
|
||||
{
|
||||
return (esp_reset_reason_t)s_reset_reason;
|
||||
}
|
||||
|
||||
#else /* CONFIG_RESET_REASON */
|
||||
|
||||
/**
|
||||
* null function for pass compiling
|
||||
*/
|
||||
void esp_reset_reason_set_hint(esp_reset_reason_t hint)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif /* CONFIG_RESET_REASON */
|
151
cpu/esp8266/vendor/esp-idf/esp8266/source/startup.c
vendored
Normal file
151
cpu/esp8266/vendor/esp-idf/esp8266/source/startup.c
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#ifndef RIOT_VERSION
|
||||
#include "tcpip_adapter.h"
|
||||
#endif
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_phy_init.h"
|
||||
#include "esp_wifi_osi.h"
|
||||
#include "esp_heap_caps_init.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "internal/esp_wifi_internal.h"
|
||||
#include "internal/esp_system_internal.h"
|
||||
|
||||
#define FLASH_MAP_ADDR 0x40200000
|
||||
#define FLASH_MAP_SIZE 0x00100000
|
||||
|
||||
extern void chip_boot(void);
|
||||
extern int esp_rtc_init(void);
|
||||
extern int mac_init(void);
|
||||
extern int base_gpio_init(void);
|
||||
extern int watchdog_init(void);
|
||||
extern int wifi_timer_init(void);
|
||||
extern int wifi_nvs_init(void);
|
||||
extern esp_err_t esp_pthread_init(void);
|
||||
extern void phy_get_bb_evm(void);
|
||||
|
||||
static void user_init_entry(void *param)
|
||||
{
|
||||
extern void app_main(void);
|
||||
|
||||
phy_get_bb_evm();
|
||||
|
||||
#ifdef MCU_ESP8266
|
||||
/* initialize newlib system calls */
|
||||
extern void syscalls_init (void);
|
||||
syscalls_init ();
|
||||
#endif
|
||||
|
||||
assert(nvs_flash_init() == 0);
|
||||
assert(wifi_nvs_init() == 0);
|
||||
assert(esp_rtc_init() == 0);
|
||||
assert(mac_init() == 0);
|
||||
assert(base_gpio_init() == 0);
|
||||
esp_phy_load_cal_and_init(0);
|
||||
assert(wifi_timer_init() == 0);
|
||||
|
||||
esp_wifi_set_rx_pbuf_mem_type(WIFI_RX_PBUF_DRAM);
|
||||
|
||||
#if CONFIG_RESET_REASON
|
||||
esp_reset_reason_init();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TASK_WDT
|
||||
esp_task_wdt_init();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ENABLE_PTHREAD
|
||||
assert(esp_pthread_init() == 0);
|
||||
#endif
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
/* initialize RIOT for ESP8266 */
|
||||
wifi_os_init();
|
||||
/* start RIOT kernel */
|
||||
wifi_os_start();
|
||||
#else
|
||||
app_main();
|
||||
|
||||
wifi_task_delete(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void call_user_start(size_t start_addr)
|
||||
{
|
||||
int i;
|
||||
int *p;
|
||||
|
||||
extern int _bss_start, _bss_end;
|
||||
|
||||
esp_image_header_t *head = (esp_image_header_t *)(FLASH_MAP_ADDR + (start_addr & (FLASH_MAP_SIZE - 1)));
|
||||
esp_image_segment_header_t *segment = (esp_image_segment_header_t *)((uintptr_t)head + sizeof(esp_image_header_t));
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
segment = (esp_image_segment_header_t *)((uintptr_t)segment + sizeof(esp_image_segment_header_t) + segment->data_len);
|
||||
|
||||
uint32_t *dest = (uint32_t *)segment->load_addr;
|
||||
uint32_t *src = (uint32_t *)((uintptr_t)segment + sizeof(esp_image_segment_header_t));
|
||||
uint32_t size = segment->data_len / sizeof(uint32_t);
|
||||
|
||||
while (size--)
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
/*
|
||||
* When finish copying IRAM program, the exception vect must be initialized.
|
||||
* And then user can load/store data which is not aligned by 4-byte.
|
||||
*/
|
||||
__asm__ __volatile__(
|
||||
"movi a0, 0x40100000\n"
|
||||
"wsr a0, vecbase\n"
|
||||
: : :"memory");
|
||||
|
||||
#ifndef CONFIG_BOOTLOADER_INIT_SPI_FLASH
|
||||
chip_boot();
|
||||
#endif
|
||||
|
||||
/* clear bss data */
|
||||
for (p = &_bss_start; p < &_bss_end; p++)
|
||||
*p = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"rsil a2, 2\n"
|
||||
"movi a1, _chip_interrupt_tmp\n"
|
||||
: : :"memory");
|
||||
|
||||
heap_caps_init();
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
/* in case of RIOT, user_init_entry is called directly and not from a task */
|
||||
user_init_entry(NULL);
|
||||
#else
|
||||
wifi_os_init();
|
||||
|
||||
assert(wifi_task_create(user_init_entry, "uiT", CONFIG_MAIN_TASK_STACK_SIZE, NULL, wifi_task_get_max_priority()) != NULL);
|
||||
|
||||
wifi_os_start();
|
||||
#endif
|
||||
}
|
357
cpu/esp8266/vendor/esp-idf/esp8266/source/system_api.c
vendored
Normal file
357
cpu/esp8266/vendor/esp-idf/esp8266/source/system_api.c
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
#include "esp8266/eagle_soc.h"
|
||||
#include "esp8266/efuse_register.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char* TAG = "system_api";
|
||||
|
||||
static uint8_t base_mac_addr[6] = { 0 };
|
||||
|
||||
esp_err_t esp_base_mac_addr_set(uint8_t *mac)
|
||||
{
|
||||
if (mac == NULL) {
|
||||
ESP_LOGE(TAG, "Base MAC address is NULL");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
memcpy(base_mac_addr, mac, 6);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_base_mac_addr_get(uint8_t *mac)
|
||||
{
|
||||
uint8_t null_mac[6] = {0};
|
||||
|
||||
if (memcmp(base_mac_addr, null_mac, 6) == 0) {
|
||||
ESP_LOGI(TAG, "Base MAC address is not set, read default base MAC address from BLK0 of EFUSE");
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
}
|
||||
|
||||
memcpy(mac, base_mac_addr, 6);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_efuse_mac_get_default(uint8_t* mac)
|
||||
{
|
||||
uint32_t efuse[4];
|
||||
|
||||
uint8_t efuse_crc = 0;
|
||||
uint8_t calc_crc = 0;
|
||||
uint8_t version;
|
||||
uint8_t use_default = 1;
|
||||
|
||||
efuse[0] = REG_READ(EFUSE_DATA0_REG);
|
||||
efuse[1] = REG_READ(EFUSE_DATA1_REG);
|
||||
efuse[2] = REG_READ(EFUSE_DATA2_REG);
|
||||
efuse[3] = REG_READ(EFUSE_DATA3_REG);
|
||||
|
||||
mac[3] = efuse[1] >> 8;
|
||||
mac[4] = efuse[1];
|
||||
mac[5] = efuse[0] >> 24;
|
||||
|
||||
if (efuse[2] & EFUSE_IS_48BITS_MAC) {
|
||||
uint8_t tmp_mac[4];
|
||||
|
||||
mac[0] = efuse[3] >> 16;
|
||||
mac[1] = efuse[3] >> 8;
|
||||
mac[2] = efuse[3];
|
||||
|
||||
use_default = 0;
|
||||
|
||||
tmp_mac[0] = mac[2];
|
||||
tmp_mac[1] = mac[1];
|
||||
tmp_mac[2] = mac[0];
|
||||
|
||||
efuse_crc = efuse[2] >> 24;
|
||||
calc_crc = esp_crc8(tmp_mac, 3);
|
||||
|
||||
if (efuse_crc != calc_crc)
|
||||
use_default = 1;
|
||||
|
||||
if (!use_default) {
|
||||
version = (efuse[1] >> EFUSE_VERSION_S) & EFUSE_VERSION_V;
|
||||
|
||||
if (version == EFUSE_VERSION_1 || version == EFUSE_VERSION_2) {
|
||||
tmp_mac[0] = mac[5];
|
||||
tmp_mac[1] = mac[4];
|
||||
tmp_mac[2] = mac[3];
|
||||
tmp_mac[3] = efuse[1] >> 16;
|
||||
|
||||
efuse_crc = efuse[0] >> 16;
|
||||
calc_crc = esp_crc8(tmp_mac, 4);
|
||||
|
||||
if (efuse_crc != calc_crc)
|
||||
use_default = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (use_default) {
|
||||
mac[0] = 0x18;
|
||||
mac[1] = 0xFE;
|
||||
mac[2] = 0x34;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static const char *BACKUP_MAC_NAMESPACE = "backup_mac";
|
||||
static const char *BACKUP_MAC_DATA_KEY = "backup_mac_data";
|
||||
#define MAC_DATA_LEN_WITH_CRC (4*4)
|
||||
|
||||
static esp_err_t load_backup_mac_data(uint8_t *mac)
|
||||
{
|
||||
esp_err_t err;
|
||||
nvs_handle handle;
|
||||
uint32_t efuse[4];
|
||||
uint8_t efuse_crc = 0;
|
||||
uint8_t calc_crc = 0;
|
||||
uint8_t version;
|
||||
|
||||
if (mac == NULL) {
|
||||
ESP_LOGE(TAG, "mac address param is NULL");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
err = nvs_open(BACKUP_MAC_NAMESPACE, NVS_READONLY, &handle);
|
||||
|
||||
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
|
||||
ESP_LOGE(TAG, "%s: NVS has not been initialized. "
|
||||
"Call nvs_flash_init before starting WiFi/BT.", __func__);
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
} else if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
}
|
||||
|
||||
size_t length = MAC_DATA_LEN_WITH_CRC;
|
||||
err = nvs_get_blob(handle, BACKUP_MAC_DATA_KEY, efuse, &length);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: failed to get backup mac (0x%x)", __func__, err);
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
}
|
||||
if (length != MAC_DATA_LEN_WITH_CRC) {
|
||||
ESP_LOGD(TAG, "%s: invalid length of backup mac (%d)", __func__, length);
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
}
|
||||
nvs_close(handle);
|
||||
|
||||
mac[3] = efuse[1] >> 8;
|
||||
mac[4] = efuse[1];
|
||||
mac[5] = efuse[0] >> 24;
|
||||
|
||||
if (efuse[2] & EFUSE_IS_48BITS_MAC) {
|
||||
uint8_t tmp_mac[4];
|
||||
|
||||
mac[0] = efuse[3] >> 16;
|
||||
mac[1] = efuse[3] >> 8;
|
||||
mac[2] = efuse[3];
|
||||
|
||||
tmp_mac[0] = mac[2];
|
||||
tmp_mac[1] = mac[1];
|
||||
tmp_mac[2] = mac[0];
|
||||
|
||||
efuse_crc = efuse[2] >> 24;
|
||||
calc_crc = esp_crc8(tmp_mac, 3);
|
||||
|
||||
if (efuse_crc != calc_crc) {
|
||||
ESP_LOGE(TAG, "High MAC CRC error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc);
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
}
|
||||
|
||||
version = (efuse[1] >> EFUSE_VERSION_S) & EFUSE_VERSION_V;
|
||||
|
||||
if (version == EFUSE_VERSION_1 || version == EFUSE_VERSION_2) {
|
||||
tmp_mac[0] = mac[5];
|
||||
tmp_mac[1] = mac[4];
|
||||
tmp_mac[2] = mac[3];
|
||||
tmp_mac[3] = efuse[1] >> 16;
|
||||
|
||||
efuse_crc = efuse[0] >> 16;
|
||||
calc_crc = esp_crc8(tmp_mac, 4);
|
||||
|
||||
if (efuse_crc != calc_crc) {
|
||||
ESP_LOGE(TAG, "CRC8 error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc);
|
||||
return ESP_ERR_INVALID_MAC;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mac[0] = 0x18;
|
||||
mac[1] = 0xFE;
|
||||
mac[2] = 0x34;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t store_backup_mac_data(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
nvs_handle handle;
|
||||
uint32_t efuse[4];
|
||||
efuse[0] = REG_READ(EFUSE_DATA0_REG);
|
||||
efuse[1] = REG_READ(EFUSE_DATA1_REG);
|
||||
efuse[2] = REG_READ(EFUSE_DATA2_REG);
|
||||
efuse[3] = REG_READ(EFUSE_DATA3_REG);
|
||||
|
||||
err = nvs_open(BACKUP_MAC_NAMESPACE, NVS_READWRITE, &handle);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_set_blob(handle, BACKUP_MAC_DATA_KEY, efuse, MAC_DATA_LEN_WITH_CRC);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: store backup mac data failed(0x%x)\n", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_commit(handle);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: store backup mac data failed(0x%x)\n", __func__, err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_derive_mac(uint8_t* local_mac, const uint8_t* universal_mac)
|
||||
{
|
||||
uint8_t idx;
|
||||
|
||||
if (local_mac == NULL || universal_mac == NULL) {
|
||||
ESP_LOGE(TAG, "mac address param is NULL");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
memcpy(local_mac, universal_mac, 6);
|
||||
for (idx = 0; idx < 64; idx++) {
|
||||
local_mac[0] = universal_mac[0] | 0x02;
|
||||
local_mac[0] ^= idx << 2;
|
||||
|
||||
if (memcmp(local_mac, universal_mac, 6)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
|
||||
{
|
||||
uint8_t efuse_mac[6];
|
||||
|
||||
if (mac == NULL) {
|
||||
ESP_LOGE(TAG, "mac address param is NULL");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (type < ESP_MAC_WIFI_STA || type > ESP_MAC_WIFI_SOFTAP) {
|
||||
ESP_LOGE(TAG, "mac type is incorrect");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (esp_base_mac_addr_get(efuse_mac) != ESP_OK) {
|
||||
if (load_backup_mac_data(efuse_mac) != ESP_OK) {
|
||||
if (esp_efuse_mac_get_default(efuse_mac) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Get mac address error");
|
||||
abort();
|
||||
} else {
|
||||
store_backup_mac_data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ESP_MAC_WIFI_STA:
|
||||
memcpy(mac, efuse_mac, 6);
|
||||
break;
|
||||
case ESP_MAC_WIFI_SOFTAP:
|
||||
esp_derive_mac(mac, efuse_mac);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "incorrect mac type");
|
||||
break;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IDF version
|
||||
*/
|
||||
const char* esp_get_idf_version(void)
|
||||
{
|
||||
return IDF_VER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fill an esp_chip_info_t structure with information about the ESP8266 chip
|
||||
*/
|
||||
static void get_chip_info_esp8266(esp_chip_info_t* out_info)
|
||||
{
|
||||
memset(out_info, 0, sizeof(*out_info));
|
||||
|
||||
out_info->model = CHIP_ESP8266;
|
||||
out_info->revision = 1;
|
||||
out_info->cores = 1;
|
||||
out_info->features = CHIP_FEATURE_WIFI_BGN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fill an esp_chip_info_t structure with information about the chip
|
||||
*/
|
||||
void esp_chip_info(esp_chip_info_t* out_info)
|
||||
{
|
||||
// Only ESP8266 is supported now, in the future call one of the
|
||||
// chip-specific functions based on sdkconfig choice
|
||||
return get_chip_info_esp8266(out_info);
|
||||
}
|
||||
|
||||
#ifdef MODULE_ESP_IDF_HEAP
|
||||
/**
|
||||
* @brief Get the size of available heap.
|
||||
*/
|
||||
uint32_t esp_get_free_heap_size(void)
|
||||
{
|
||||
return heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the minimum heap that has ever been available
|
||||
*/
|
||||
uint32_t esp_get_minimum_free_heap_size(void)
|
||||
{
|
||||
return heap_caps_get_minimum_free_size(MALLOC_CAP_32BIT);
|
||||
}
|
||||
#endif /* MODULE_ESP_IDF_HEAP */
|
115
cpu/esp8266/vendor/esp-idf/esp8266/source/task_wdt.c
vendored
Normal file
115
cpu/esp8266/vendor/esp-idf/esp8266/source/task_wdt.c
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_libc.h"
|
||||
#include "esp_wifi_osi.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "portmacro.h"
|
||||
#include "esp8266/eagle_soc.h"
|
||||
|
||||
static const char *TAG = "wdt";
|
||||
|
||||
#ifdef CONFIG_TASK_WDT_PANIC
|
||||
/**
|
||||
* @brief Task watch dog interrupt function and it should do panic
|
||||
*/
|
||||
static void esp_task_wdt_isr(void *param)
|
||||
{
|
||||
/*
|
||||
* In RIOT-OS, the interrupt from WDT (stage 1) is only used to wakeup
|
||||
* the system and to execute `sched_run` on the exit from the interrupt
|
||||
* to schedule the next task which also resets the WDT.
|
||||
* The system is hard-reset (stage 2), if the system is locked completely.
|
||||
*/
|
||||
#ifdef RIOT_VERSION
|
||||
esp_task_wdt_reset();
|
||||
#else
|
||||
extern void panicHandler(void *frame, int wdt);
|
||||
|
||||
panicHandler(osi_task_top_sp(), 1);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Just for pass compiling and mark wdt calling line
|
||||
*/
|
||||
typedef void (* _xt_isr)(void *arg);
|
||||
extern void _xt_isr_unmask(uint32_t unmask);
|
||||
extern void _xt_clear_ints(uint32_t mask);
|
||||
extern void _xt_isr_attach(uint8_t i, _xt_isr func, void *arg);
|
||||
|
||||
esp_err_t esp_task_wdt_init(void)
|
||||
{
|
||||
CLEAR_WDT_REG_MASK(WDT_CTL_ADDRESS, BIT0);
|
||||
|
||||
#ifdef CONFIG_TASK_WDT_PANIC
|
||||
const uint32_t panic_time_param = 11;
|
||||
|
||||
// Just for soft restart
|
||||
_xt_clear_ints(1 << ETS_WDT_INUM);
|
||||
|
||||
_xt_isr_attach(ETS_WDT_INUM, esp_task_wdt_isr, NULL);
|
||||
_xt_isr_unmask(1 << ETS_WDT_INUM);
|
||||
|
||||
WDT_EDGE_INT_ENABLE();
|
||||
|
||||
ESP_LOGD(TAG, "Enable task watch dog panic, panic time parameter is %u", panic_time_param);
|
||||
#else
|
||||
const uint32_t panic_time_param = 1;
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, "task watch dog trigger time parameter is %u", CONFIG_TASK_WDT_TIMEOUT_S);
|
||||
|
||||
WDT_REG_WRITE(WDT_OP_ADDRESS, CONFIG_TASK_WDT_TIMEOUT_S); // 2^n * 0.8ms, mask 0xf, n = 13 -> (2^13 = 8192) * 0.8 * 0.001 = 6.5536
|
||||
WDT_REG_WRITE(WDT_OP_ND_ADDRESS, panic_time_param); // 2^n * 0.8ms, mask 0xf, n = 11 -> (2^11 = 2048) * 0.8 * 0.001 = 1.6384
|
||||
|
||||
SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_RSTLEN_MASK, 7 << WDT_CTL_RSTLEN_LSB, 0);
|
||||
// interrupt then reset
|
||||
SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_RSPMOD_MASK, 0 << WDT_CTL_RSPMOD_LSB, 0);
|
||||
// start task watch dog1
|
||||
SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_EN_MASK, 1 << WDT_CTL_EN_LSB, 0);
|
||||
|
||||
WDT_FEED();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset(Feed) the Task Watchdog Timer (TWDT) on behalf of the currently
|
||||
* running task
|
||||
*/
|
||||
void esp_task_wdt_reset(void)
|
||||
{
|
||||
WDT_FEED();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Just for pass compiling and mark wdt calling line
|
||||
*/
|
||||
void pp_soft_wdt_stop(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Just for pass compiling and mark wdt calling line
|
||||
*/
|
||||
void pp_soft_wdt_restart(void)
|
||||
{
|
||||
|
||||
}
|
90
cpu/esp8266/vendor/esp-idf/esp_funcs.c
vendored
Normal file
90
cpu/esp8266/vendor/esp-idf/esp_funcs.c
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Gunar Schorcht
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_esp8266
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief ESP function required by SDK
|
||||
*
|
||||
* This file is a collection of functions required by ESP8266 RTOS SDK.
|
||||
*
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*/
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "assert.h"
|
||||
#include "esp/xtensa_ops.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_libc.h"
|
||||
#include "irq_arch.h"
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "xtensa/xtensa_api.h"
|
||||
|
||||
/* Just to satisfy the linker, lwIP from SDK is not used */
|
||||
uint32_t LwipTimOutLim = 0;
|
||||
|
||||
#ifndef MODULE_LWIP_ETHERNET
|
||||
const uint8_t ethbroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
#endif
|
||||
|
||||
void IRAM_ATTR HDL_MAC_SIG_IN_LV1_ISR(void)
|
||||
{
|
||||
extern unsigned int ets_soft_int_type;
|
||||
ets_soft_int_type = ETS_SOFT_INT_HDL_MAC;
|
||||
WSR(BIT(ETS_SOFT_INUM), interrupt);
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
|
||||
{
|
||||
printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x at %p\n", rc, __builtin_return_address(0));
|
||||
printf("file: \"%s\" line %d\nfunc: %s\nexpression: %s\n", file, line, function, expression);
|
||||
abort();
|
||||
}
|
||||
|
||||
void IRAM_ATTR _xt_isr_attach(uint8_t i, xt_handler func, void* arg)
|
||||
{
|
||||
DEBUG("%s %d %p\n", __func__, i, func);
|
||||
xt_set_interrupt_handler(i, func, arg);
|
||||
}
|
||||
|
||||
|
||||
unsigned int IRAM_ATTR _xt_isr_unmask(unsigned int mask)
|
||||
{
|
||||
DEBUG("%s %08x\n", __func__, mask);
|
||||
return xt_ints_on(mask);
|
||||
}
|
||||
|
||||
unsigned int IRAM_ATTR _xt_isr_mask(unsigned int mask)
|
||||
{
|
||||
DEBUG("%s %08x\n", __func__, mask);
|
||||
return xt_ints_off(mask);
|
||||
}
|
||||
|
||||
void IRAM_ATTR _xt_clear_ints(uint32_t mask)
|
||||
{
|
||||
DEBUG("%s %08x\n", __func__, mask);
|
||||
xt_set_intclear(mask);
|
||||
}
|
||||
|
||||
void IRAM_ATTR _xt_set_xt_ccompare_val(void)
|
||||
{
|
||||
/* to figure out whether it is called at all, not yet implemented */
|
||||
assert(0);
|
||||
DEBUG("%s\n", __func__);
|
||||
}
|
||||
|
31
cpu/esp8266/vendor/esp-idf/heap/include/esp_heap_caps_init.h
vendored
Normal file
31
cpu/esp8266/vendor/esp-idf/heap/include/esp_heap_caps_init.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize the capability-aware heap allocator.
|
||||
*
|
||||
* This is called once in the ESP8266 startup code. Do not call it
|
||||
* at other times.
|
||||
*/
|
||||
void heap_caps_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
3
cpu/esp8266/vendor/esp-idf/heap/src/Makefile
vendored
Normal file
3
cpu/esp8266/vendor/esp-idf/heap/src/Makefile
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE=esp_idf_heap
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
332
cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c
vendored
Normal file
332
cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c
vendored
Normal file
@ -0,0 +1,332 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_heap_port.h"
|
||||
#include "esp_heap_trace.h"
|
||||
#include "priv/esp_heap_caps_priv.h"
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
|
||||
#endif
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "heap_caps";
|
||||
extern heap_region_t g_heap_region[HEAP_REGIONS_MAX];
|
||||
|
||||
/**
|
||||
* @brief Initialize regions of memory to the collection of heaps at runtime.
|
||||
*/
|
||||
void esp_heap_caps_init_region(heap_region_t *region, size_t max_num)
|
||||
{
|
||||
uint8_t num;
|
||||
mem_blk_t *mem_start, *mem_end;
|
||||
|
||||
for (num = 0; num < max_num; num++) {
|
||||
mem_start = (mem_blk_t *)HEAP_ALIGN(region[num].start_addr);
|
||||
mem_end = (mem_blk_t *)(HEAP_ALIGN(region[num].start_addr + region[num].total_size));
|
||||
if ((uint8_t *)mem_end != region[num].start_addr + region[num].total_size)
|
||||
mem_end = (mem_blk_t *)((uint8_t *)mem_end - sizeof(void *));
|
||||
mem_end = (mem_blk_t *)((uint8_t *)mem_end - MEM_HEAD_SIZE);
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "heap %d start from %p to %p total %d bytes, mem_blk from %p to %p total",
|
||||
num, region[num].start_addr, region[num].start_addr + region[num].total_size,
|
||||
region[num].total_size, mem_start, mem_end);
|
||||
|
||||
mem_start->prev = NULL;
|
||||
mem_start->next = mem_end;
|
||||
|
||||
mem_end->prev = mem_start;
|
||||
mem_end->next = NULL;
|
||||
|
||||
g_heap_region[num].free_blk = mem_start;
|
||||
g_heap_region[num].min_free_bytes = g_heap_region[num].free_bytes = blk_link_size(mem_start);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the total free size of all the regions that have the given capabilities
|
||||
*/
|
||||
size_t heap_caps_get_free_size(uint32_t caps)
|
||||
{
|
||||
size_t bytes = 0;
|
||||
|
||||
for (int i = 0; i < HEAP_REGIONS_MAX; i++)
|
||||
if (caps == (caps & g_heap_region[i].caps))
|
||||
bytes += g_heap_region[i].free_bytes;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the total minimum free memory of all regions with the given capabilities
|
||||
*/
|
||||
size_t heap_caps_get_minimum_free_size(uint32_t caps)
|
||||
{
|
||||
size_t bytes = 0;
|
||||
|
||||
for (int i = 0; i < HEAP_REGIONS_MAX; i++)
|
||||
if (caps == (caps & g_heap_region[i].caps))
|
||||
bytes += g_heap_region[i].min_free_bytes;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocate a chunk of memory which has the given capabilities
|
||||
*/
|
||||
void *_heap_caps_malloc(size_t size, uint32_t caps, const char *file, size_t line)
|
||||
{
|
||||
mem_blk_t *mem_blk, *next_mem_blk;
|
||||
void *ret_mem = NULL;
|
||||
uint32_t num;
|
||||
uint32_t mem_blk_size;
|
||||
|
||||
if (line == 0) {
|
||||
ESP_EARLY_LOGV(TAG, "caller func %p", file);
|
||||
} else {
|
||||
ESP_EARLY_LOGV(TAG, "caller file %s line %d", file, line);
|
||||
}
|
||||
|
||||
for (num = 0; num < HEAP_REGIONS_MAX; num++) {
|
||||
bool trace;
|
||||
size_t head_size;
|
||||
|
||||
if ((g_heap_region[num].caps & caps) != caps)
|
||||
continue;
|
||||
|
||||
_heap_caps_lock(num);
|
||||
|
||||
trace = heap_trace_is_on();
|
||||
|
||||
mem_blk_size = ptr2memblk_size(size, trace);
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "malloc size is %d(%x) blk size is %d(%x) region is %d", size, size,
|
||||
mem_blk_size, mem_blk_size, num);
|
||||
|
||||
if (mem_blk_size > g_heap_region[num].free_bytes)
|
||||
goto next_region;
|
||||
|
||||
mem_blk = (mem_blk_t *)g_heap_region[num].free_blk;
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "malloc start %p", mem_blk);
|
||||
|
||||
while (mem_blk && !mem_blk_is_end(mem_blk) && (mem_blk_is_used(mem_blk) || blk_link_size(mem_blk) < mem_blk_size)) {
|
||||
ESP_EARLY_LOGV(TAG, "malloc mem_blk %p next %p used %x traced %x, size %d", mem_blk, mem_blk_next(mem_blk),
|
||||
mem_blk_is_used(mem_blk), mem_blk_is_traced(mem_blk), blk_link_size(mem_blk));
|
||||
mem_blk = mem_blk_next(mem_blk);
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "malloc end %p, end %d", mem_blk, mem_blk_is_end(mem_blk));
|
||||
|
||||
if (!mem_blk || mem_blk_is_end(mem_blk))
|
||||
goto next_region;
|
||||
|
||||
ret_mem = blk2ptr(mem_blk, trace);
|
||||
ESP_EARLY_LOGV(TAG, "ret_mem is %p", ret_mem);
|
||||
|
||||
head_size = mem_blk_head_size(trace);
|
||||
|
||||
if (blk_link_size(mem_blk) >= mem_blk_size + head_size + MEM_BLK_MIN)
|
||||
next_mem_blk = (mem_blk_t *)((uint8_t *)mem_blk + mem_blk_size);
|
||||
else
|
||||
next_mem_blk = mem_blk_next(mem_blk);
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "next_mem_blk is %p", next_mem_blk);
|
||||
|
||||
if (mem_blk_next(mem_blk) != next_mem_blk) {
|
||||
next_mem_blk->prev = next_mem_blk->next = NULL;
|
||||
|
||||
mem_blk_set_prev(next_mem_blk, mem_blk);
|
||||
mem_blk_set_next(next_mem_blk, mem_blk_next(mem_blk));
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "mem_blk1 %p, mem_blk->prev %p(%p), mem_blk->next %p(%p)", mem_blk, mem_blk_prev(mem_blk),
|
||||
mem_blk->prev, mem_blk_next(mem_blk), mem_blk->next);
|
||||
|
||||
mem_blk_set_prev(mem_blk_next(mem_blk), next_mem_blk);
|
||||
mem_blk_set_next(mem_blk, next_mem_blk);
|
||||
}
|
||||
|
||||
mem_blk_set_used(mem_blk);
|
||||
if (trace) {
|
||||
mem_blk_set_traced((mem2_blk_t *)mem_blk, file, line);
|
||||
ESP_EARLY_LOGV(TAG, "mem_blk1 %p set trace", mem_blk);
|
||||
}
|
||||
|
||||
if (g_heap_region[num].free_blk == mem_blk) {
|
||||
mem_blk_t *free_blk = mem_blk;
|
||||
|
||||
while (free_blk && !mem_blk_is_end(free_blk) && mem_blk_is_used(free_blk)) {
|
||||
free_blk = mem_blk_next(free_blk);
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "reset free_blk from %p to %p", g_heap_region[num].free_blk, free_blk);
|
||||
g_heap_region[num].free_blk = free_blk;
|
||||
} else {
|
||||
ESP_EARLY_LOGV(TAG, "free_blk is %p", g_heap_region[num].free_blk);
|
||||
}
|
||||
|
||||
mem_blk_size = blk_link_size(mem_blk);
|
||||
g_heap_region[num].free_bytes -= mem_blk_size;
|
||||
|
||||
if (g_heap_region[num].min_free_bytes > g_heap_region[num].free_bytes)
|
||||
g_heap_region[num].min_free_bytes = g_heap_region[num].free_bytes;
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "mem_blk2 %p, mem_blk->prev %p(%p), mem_blk->next %p(%p)", mem_blk, mem_blk_prev(mem_blk),
|
||||
mem_blk->prev, mem_blk_next(mem_blk), mem_blk->next);
|
||||
ESP_EARLY_LOGV(TAG, "next_mem_blk %p, next_mem_blk->prev %p(%p), next_mem_blk->next %p(%p)", next_mem_blk,
|
||||
mem_blk_prev(next_mem_blk), next_mem_blk->prev, mem_blk_next(next_mem_blk), next_mem_blk->next);
|
||||
ESP_EARLY_LOGV(TAG, "last_mem_blk %p, last_mem_blk->prev %p(%p), last_mem_blk->next %p(%p)", mem_blk_next(next_mem_blk),
|
||||
mem_blk_prev(mem_blk_next(next_mem_blk)), mem_blk_next(next_mem_blk)->prev, mem_blk_next(mem_blk_next(next_mem_blk)), mem_blk_next(next_mem_blk)->next);
|
||||
|
||||
next_region:
|
||||
_heap_caps_unlock(num);
|
||||
|
||||
if (ret_mem)
|
||||
break;
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "malloc return mem %p", ret_mem);
|
||||
|
||||
return ret_mem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Free memory previously allocated via heap_caps_(m/c/r/z)alloc().
|
||||
*/
|
||||
void _heap_caps_free(void *ptr, const char *file, size_t line)
|
||||
{
|
||||
int num;
|
||||
mem_blk_t *mem_blk;
|
||||
mem_blk_t *tmp, *next, *prev, *last;
|
||||
|
||||
if ((int)line == 0) {
|
||||
ESP_EARLY_LOGV(TAG, "caller func %p", file);
|
||||
} else {
|
||||
ESP_EARLY_LOGV(TAG, "caller file %s line %d", file, line);
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
ESP_EARLY_LOGE(TAG, "free(ptr=NULL)");
|
||||
if ((int)line == 0) {
|
||||
ESP_EARLY_LOGE(TAG, "caller func %p", file);
|
||||
} else {
|
||||
ESP_EARLY_LOGE(TAG, "caller file %s line %d", file, line);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
num = get_blk_region(ptr);
|
||||
|
||||
if (num >= HEAP_REGIONS_MAX) {
|
||||
ESP_EARLY_LOGE(TAG, "free(ptr_region=NULL)");
|
||||
return;
|
||||
}
|
||||
|
||||
mem_blk = ptr2blk(ptr, ptr_is_traced(ptr));
|
||||
if (!mem_blk_is_used(mem_blk)) {
|
||||
ESP_EARLY_LOGE(TAG, "%p already freed\n", ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "Free(ptr=%p, mem_blk=%p, region=%d)", ptr, mem_blk, num);
|
||||
|
||||
_heap_caps_lock(num);
|
||||
|
||||
g_heap_region[num].free_bytes += blk_link_size(mem_blk);
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "ptr prev=%p next=%p", mem_blk_prev(mem_blk), mem_blk_next(mem_blk));
|
||||
ESP_EARLY_LOGV(TAG, "ptr1 prev->next=%p next->prev=%p", mem_blk_prev(mem_blk) ? mem_blk_next(mem_blk_prev(mem_blk)) : NULL,
|
||||
mem_blk_prev(mem_blk_next(mem_blk)));
|
||||
|
||||
mem_blk_set_unused(mem_blk);
|
||||
mem_blk_set_untraced((mem2_blk_t *)mem_blk);
|
||||
|
||||
prev = mem_blk_prev(mem_blk);
|
||||
next = mem_blk_next(mem_blk);
|
||||
last = mem_blk_next(next);
|
||||
|
||||
if (prev && !mem_blk_is_used(prev)) {
|
||||
mem_blk_set_next(prev, next);
|
||||
mem_blk_set_prev(next, prev);
|
||||
tmp = prev;
|
||||
} else
|
||||
tmp = mem_blk;
|
||||
|
||||
if (last && !mem_blk_is_used(next)) {
|
||||
mem_blk_set_next(tmp, last);
|
||||
mem_blk_set_prev(last, tmp);
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGV(TAG, "ptr2 prev->next=%p next->prev=%p", mem_blk_prev(mem_blk) ? mem_blk_next(mem_blk_prev(mem_blk)) : NULL,
|
||||
mem_blk_prev(mem_blk_next(mem_blk)));
|
||||
|
||||
if ((uint8_t *)mem_blk < (uint8_t *)g_heap_region[num].free_blk) {
|
||||
ESP_EARLY_LOGV(TAG, "Free update free block from %p to %p", g_heap_region[num].free_blk, mem_blk);
|
||||
g_heap_region[num].free_blk = mem_blk;
|
||||
}
|
||||
|
||||
_heap_caps_unlock(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocate a chunk of memory which has the given capabilities. The initialized value in the memory is set to zero.
|
||||
*/
|
||||
void *_heap_caps_calloc(size_t count, size_t size, uint32_t caps, const char *file, size_t line)
|
||||
{
|
||||
void *p = _heap_caps_malloc(count * size, caps, file, line);
|
||||
if (p)
|
||||
memset(p, 0, count * size);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reallocate memory previously allocated via heap_caps_(m/c/r/z)alloc().
|
||||
*/
|
||||
void *_heap_caps_realloc(void *mem, size_t newsize, uint32_t caps, const char *file, size_t line)
|
||||
{
|
||||
void *return_addr = (void *)__builtin_return_address(0);
|
||||
|
||||
void *p = _heap_caps_malloc(newsize, caps, file, line);
|
||||
if (p && mem) {
|
||||
size_t mem_size = ptr_size(mem);
|
||||
size_t min = MIN(newsize, mem_size);
|
||||
|
||||
memcpy(p, mem, min);
|
||||
_heap_caps_free(mem, (char *)return_addr, line);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocate a chunk of memory which has the given capabilities. The initialized value in the memory is set to zero.
|
||||
*/
|
||||
void *_heap_caps_zalloc(size_t size, uint32_t caps, const char *file, size_t line)
|
||||
{
|
||||
void *p = _heap_caps_malloc(size, caps, file, line);
|
||||
if (p)
|
||||
memset(p, 0, size);
|
||||
|
||||
return p;
|
||||
}
|
39
cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_init.c
vendored
Normal file
39
cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_init.c
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
heap_region_t g_heap_region[HEAP_REGIONS_MAX];
|
||||
|
||||
/**
|
||||
* @brief Initialize the capability-aware heap allocator.
|
||||
*/
|
||||
void heap_caps_init(void)
|
||||
{
|
||||
extern char _heap_start;
|
||||
|
||||
#ifndef CONFIG_SOC_FULL_ICACHE
|
||||
extern char _lit4_end;
|
||||
|
||||
g_heap_region[0].start_addr = (uint8_t *)&_lit4_end;
|
||||
g_heap_region[0].total_size = ((size_t)(0x4010C000 - (uint32_t)&_lit4_end));
|
||||
g_heap_region[0].caps = MALLOC_CAP_32BIT;
|
||||
#endif
|
||||
|
||||
g_heap_region[HEAP_REGIONS_MAX - 1].start_addr = (uint8_t *)&_heap_start;
|
||||
g_heap_region[HEAP_REGIONS_MAX - 1].total_size = ((size_t)(0x40000000 - (uint32_t)&_heap_start));
|
||||
g_heap_region[HEAP_REGIONS_MAX - 1].caps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_DMA;
|
||||
|
||||
esp_heap_caps_init_region(g_heap_region, HEAP_REGIONS_MAX);
|
||||
}
|
146
cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_trace.c
vendored
Normal file
146
cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_trace.c
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_heap_port.h"
|
||||
#include "esp_heap_trace.h"
|
||||
#include "priv/esp_heap_caps_priv.h"
|
||||
|
||||
//#define CONFIG_TRACE_ALL
|
||||
//#define CONFIG_TRACE_MEM_LINK 1
|
||||
//#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
#ifdef CONFIG_TRACE_ALL
|
||||
#define HEAP_INFO_STATE " is %s"
|
||||
#define HEAP_INFO_STATE_PARAM(_p) ,mem_blk_is_used(_p)?"used":"freed"
|
||||
#else
|
||||
#define HEAP_INFO_STATE ""
|
||||
#define HEAP_INFO_STATE_PARAM(_p)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TRACE_MEM_LINK
|
||||
#define HEAP_INFO "p %p, prev %p(%p) next %p(%p) size %d"HEAP_INFO_STATE
|
||||
#define HEAP_INFO_PARAM(_p) (_p),mem_blk_prev(_p),(_p)->prev,mem_blk_next(_p),(_p)->next,blk_link_size(_p)HEAP_INFO_STATE_PARAM(_p)
|
||||
#else
|
||||
#define HEAP_INFO "mem @%p size %d"HEAP_INFO_STATE
|
||||
#define HEAP_INFO_PARAM(_p) (_p),blk_link_size(_p)HEAP_INFO_STATE_PARAM(_p)
|
||||
#endif
|
||||
|
||||
static const char *TAG = "heap_trace";
|
||||
static int s_heap_trace_mode = HEAP_TRACE_NONE;
|
||||
extern heap_region_t g_heap_region[HEAP_REGIONS_MAX];
|
||||
|
||||
/**
|
||||
* @brief Empty function just for passing compiling some place.
|
||||
*/
|
||||
esp_err_t heap_trace_init_standalone(heap_trace_record_t *record_buffer, size_t num_records)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if heap trace is on
|
||||
*/
|
||||
int heap_trace_is_on(void)
|
||||
{
|
||||
return s_heap_trace_mode == HEAP_TRACE_LEAKS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start heap tracing. All heap allocations will be traced, until heap_trace_stop() is called.
|
||||
*/
|
||||
esp_err_t heap_trace_start(heap_trace_mode_t mode)
|
||||
{
|
||||
s_heap_trace_mode = mode;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop heap tracing.
|
||||
*/
|
||||
esp_err_t heap_trace_stop(void)
|
||||
{
|
||||
s_heap_trace_mode = HEAP_TRACE_NONE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume heap tracing which was previously stopped.
|
||||
*/
|
||||
esp_err_t heap_trace_resume(void)
|
||||
{
|
||||
s_heap_trace_mode = HEAP_TRACE_LEAKS;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump heap trace record data to stdout
|
||||
*/
|
||||
void heap_trace_dump(void)
|
||||
{
|
||||
uint8_t num;
|
||||
mem_blk_t *mem_start, *mem_end, *p;
|
||||
|
||||
for (num = 0; num < HEAP_REGIONS_MAX; num++) {
|
||||
mem_start = (mem_blk_t *)HEAP_ALIGN(g_heap_region[num].start_addr);
|
||||
mem_end = (mem_blk_t *)(HEAP_ALIGN(g_heap_region[num].start_addr + g_heap_region[num].total_size));
|
||||
if ((uint8_t *)mem_end != g_heap_region[num].start_addr + g_heap_region[num].total_size)
|
||||
mem_end = (mem_blk_t *)((uint8_t *)mem_end - sizeof(void *));
|
||||
mem_end = (mem_blk_t *)((uint8_t *)mem_end - MEM_HEAD_SIZE);
|
||||
|
||||
_heap_caps_lock(num);
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "\r\n\r\n");
|
||||
ESP_EARLY_LOGD(TAG, "start %p end %p", mem_start, mem_end);
|
||||
ESP_EARLY_LOGD(TAG, "free blk %p", g_heap_region[num].free_blk);
|
||||
ESP_EARLY_LOGD(TAG, "size %d mini size %d", g_heap_region[num].free_bytes, g_heap_region[num].min_free_bytes);
|
||||
|
||||
p = mem_start;
|
||||
while (p != mem_end) {
|
||||
if (mem_blk_is_used(p) && mem_blk_is_traced(p)) {
|
||||
mem2_blk_t *mem2_blk = (mem2_blk_t *)p;
|
||||
size_t line = mem2_blk_line(mem2_blk);
|
||||
|
||||
if (!line) {
|
||||
ESP_EARLY_LOGI(TAG, HEAP_INFO " caller func %p", HEAP_INFO_PARAM(p), mem2_blk->file);
|
||||
} else {
|
||||
const char *file = rindex(mem2_blk->file, '/');
|
||||
if (file)
|
||||
file++;
|
||||
else
|
||||
file = mem2_blk->file;
|
||||
|
||||
ESP_EARLY_LOGI(TAG, HEAP_INFO " caller file %s line %d", HEAP_INFO_PARAM(p), file, line);
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_TRACE_ALL
|
||||
else {
|
||||
ESP_EARLY_LOGI(TAG, HEAP_INFO, HEAP_INFO_PARAM(p));
|
||||
}
|
||||
#endif
|
||||
p = mem_blk_next(p);
|
||||
|
||||
_heap_caps_feed_wdt(g_heap_region[num].caps & caps);
|
||||
}
|
||||
|
||||
_heap_caps_unlock(num);
|
||||
}
|
||||
}
|
357
cpu/esp8266/vendor/esp-idf/log/include/esp_log.h
vendored
Normal file
357
cpu/esp8266/vendor/esp-idf/log/include/esp_log.h
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
// Copyright 2015-2016 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 LOG_ESP_LOG_H
|
||||
#define LOG_ESP_LOG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include "sdk_conf.h"
|
||||
#include <rom/ets_sys.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Log level
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_LOG_NONE, /*!< No log output */
|
||||
ESP_LOG_ERROR, /*!< Critical errors, software module can not recover on its own */
|
||||
ESP_LOG_WARN, /*!< Error conditions from which recovery measures have been taken */
|
||||
ESP_LOG_INFO, /*!< Information messages which describe normal flow of events */
|
||||
ESP_LOG_DEBUG, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
|
||||
ESP_LOG_VERBOSE /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
|
||||
} esp_log_level_t;
|
||||
|
||||
typedef int (*vprintf_like_t)(const char *, va_list);
|
||||
|
||||
/**
|
||||
* @brief Set log level for given tag
|
||||
*
|
||||
* If logging for given component has already been enabled, changes previous setting.
|
||||
*
|
||||
* Note that this function can not raise log level above the level set using
|
||||
* CONFIG_LOG_DEFAULT_LEVEL setting in menuconfig.
|
||||
*
|
||||
* To raise log level above the default one for a given file, define
|
||||
* LOG_LOCAL_LEVEL to one of the ESP_LOG_* values, before including
|
||||
* esp_log.h in this file.
|
||||
*
|
||||
* @param tag Tag of the log entries to enable. Must be a non-NULL zero terminated string.
|
||||
* Value "*" resets log level for all tags to the given value.
|
||||
*
|
||||
* @param level Selects log level to enable. Only logs at this and lower verbosity
|
||||
* levels will be shown.
|
||||
*/
|
||||
void esp_log_level_set(const char* tag, esp_log_level_t level);
|
||||
|
||||
/**
|
||||
* @brief Set function used to output log entries
|
||||
*
|
||||
* By default, log output goes to UART0. This function can be used to redirect log
|
||||
* output to some other destination, such as file or network. Returns the original
|
||||
* log handler, which may be necessary to return output to the previous destination.
|
||||
*
|
||||
* @param func new Function used for output. Must have same signature as vprintf.
|
||||
*
|
||||
* @return func old Function used for output.
|
||||
*/
|
||||
vprintf_like_t esp_log_set_vprintf(vprintf_like_t func);
|
||||
|
||||
/**
|
||||
* @brief Function which returns timestamp to be used in log output
|
||||
*
|
||||
* This function is used in expansion of ESP_LOGx macros.
|
||||
* In the 2nd stage bootloader, and at early application startup stage
|
||||
* this function uses CPU cycle counter as time source. Later when
|
||||
* FreeRTOS scheduler start running, it switches to FreeRTOS tick count.
|
||||
*
|
||||
* For now, we ignore millisecond counter overflow.
|
||||
*
|
||||
* @return timestamp, in milliseconds
|
||||
*/
|
||||
uint32_t esp_log_timestamp(void);
|
||||
|
||||
/**
|
||||
* @brief Function which returns timestamp to be used in log output
|
||||
*
|
||||
* This function uses HW cycle counter and does not depend on OS,
|
||||
* so it can be safely used after application crash.
|
||||
*
|
||||
* @return timestamp, in milliseconds
|
||||
*/
|
||||
uint32_t esp_log_early_timestamp(void);
|
||||
|
||||
/**
|
||||
* @brief Write message into the log
|
||||
*
|
||||
* This function is not intended to be used directly. Instead, use one of
|
||||
* ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV macros.
|
||||
*
|
||||
* This function or these macros should not be used from an interrupt.
|
||||
*/
|
||||
void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
|
||||
#ifndef RIOT_VERSION
|
||||
|
||||
/** @cond */
|
||||
|
||||
#include "esp_log_internal.h"
|
||||
|
||||
#ifndef LOG_LOCAL_LEVEL
|
||||
#ifndef BOOTLOADER_BUILD
|
||||
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
||||
#else
|
||||
#define LOG_LOCAL_LEVEL CONFIG_LOG_BOOTLOADER_LEVEL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief Log a buffer of hex bytes at specified level, separated into 16 bytes each line.
|
||||
*
|
||||
* @param tag description tag
|
||||
* @param buffer Pointer to the buffer array
|
||||
* @param buff_len length of buffer in bytes
|
||||
* @param level level of the log
|
||||
*
|
||||
*/
|
||||
#define ESP_LOG_BUFFER_HEX_LEVEL( tag, buffer, buff_len, level ) \
|
||||
do {\
|
||||
if ( LOG_LOCAL_LEVEL >= (level) ) { \
|
||||
esp_log_buffer_hex_internal( tag, buffer, buff_len, level ); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Log a buffer of characters at specified level, separated into 16 bytes each line. Buffer should contain only printable characters.
|
||||
*
|
||||
* @param tag description tag
|
||||
* @param buffer Pointer to the buffer array
|
||||
* @param buff_len length of buffer in bytes
|
||||
* @param level level of the log
|
||||
*
|
||||
*/
|
||||
#define ESP_LOG_BUFFER_CHAR_LEVEL( tag, buffer, buff_len, level ) \
|
||||
do {\
|
||||
if ( LOG_LOCAL_LEVEL >= (level) ) { \
|
||||
esp_log_buffer_char_internal( tag, buffer, buff_len, level ); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Dump a buffer to the log at specified level.
|
||||
*
|
||||
* The dump log shows just like the one below:
|
||||
*
|
||||
* W (195) log_example: 0x3ffb4280 45 53 50 33 32 20 69 73 20 67 72 65 61 74 2c 20 |ESP32 is great, |
|
||||
* W (195) log_example: 0x3ffb4290 77 6f 72 6b 69 6e 67 20 61 6c 6f 6e 67 20 77 69 |working along wi|
|
||||
* W (205) log_example: 0x3ffb42a0 74 68 20 74 68 65 20 49 44 46 2e 00 |th the IDF..|
|
||||
*
|
||||
* It is highly recommend to use terminals with over 102 text width.
|
||||
*
|
||||
* @param tag description tag
|
||||
* @param buffer Pointer to the buffer array
|
||||
* @param buff_len length of buffer in bytes
|
||||
* @param level level of the log
|
||||
*/
|
||||
#define ESP_LOG_BUFFER_HEXDUMP( tag, buffer, buff_len, level ) \
|
||||
do { \
|
||||
if ( LOG_LOCAL_LEVEL >= (level) ) { \
|
||||
esp_log_buffer_hexdump_internal( tag, buffer, buff_len, level); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Log a buffer of hex bytes at Info level
|
||||
*
|
||||
* @param tag description tag
|
||||
* @param buffer Pointer to the buffer array
|
||||
* @param buff_len length of buffer in bytes
|
||||
*
|
||||
* @see ``esp_log_buffer_hex_level``
|
||||
*
|
||||
*/
|
||||
#define ESP_LOG_BUFFER_HEX(tag, buffer, buff_len) \
|
||||
do { \
|
||||
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { \
|
||||
ESP_LOG_BUFFER_HEX_LEVEL( tag, buffer, buff_len, ESP_LOG_INFO ); \
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Log a buffer of characters at Info level. Buffer should contain only printable characters.
|
||||
*
|
||||
* @param tag description tag
|
||||
* @param buffer Pointer to the buffer array
|
||||
* @param buff_len length of buffer in bytes
|
||||
*
|
||||
* @see ``esp_log_buffer_char_level``
|
||||
*
|
||||
*/
|
||||
#define ESP_LOG_BUFFER_CHAR(tag, buffer, buff_len) \
|
||||
do { \
|
||||
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { \
|
||||
ESP_LOG_BUFFER_CHAR_LEVEL( tag, buffer, buff_len, ESP_LOG_INFO ); \
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
/** @cond */
|
||||
|
||||
//to be back compatible
|
||||
#define esp_log_buffer_hex ESP_LOG_BUFFER_HEX
|
||||
#define esp_log_buffer_char ESP_LOG_BUFFER_CHAR
|
||||
|
||||
|
||||
#if CONFIG_LOG_COLORS
|
||||
#define LOG_COLOR_BLACK "30"
|
||||
#define LOG_COLOR_RED "31"
|
||||
#define LOG_COLOR_GREEN "32"
|
||||
#define LOG_COLOR_BROWN "33"
|
||||
#define LOG_COLOR_BLUE "34"
|
||||
#define LOG_COLOR_PURPLE "35"
|
||||
#define LOG_COLOR_CYAN "36"
|
||||
#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
|
||||
#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
|
||||
#define LOG_RESET_COLOR "\033[0m"
|
||||
#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
|
||||
#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
|
||||
#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
|
||||
#define LOG_COLOR_D
|
||||
#define LOG_COLOR_V
|
||||
#else //CONFIG_LOG_COLORS
|
||||
#define LOG_COLOR_E
|
||||
#define LOG_COLOR_W
|
||||
#define LOG_COLOR_I
|
||||
#define LOG_COLOR_D
|
||||
#define LOG_COLOR_V
|
||||
#define LOG_RESET_COLOR
|
||||
#endif //CONFIG_LOG_COLORS
|
||||
|
||||
#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%d) %s: " format LOG_RESET_COLOR "\n"
|
||||
|
||||
/** @endcond */
|
||||
|
||||
/// macro to output logs in startup code, before heap allocator and syscalls have been initialized. log at ``ESP_LOG_ERROR`` level. @see ``printf``,``ESP_LOGE``
|
||||
#define ESP_EARLY_LOGE( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_ERROR, E, ##__VA_ARGS__)
|
||||
/// macro to output logs in startup code at ``ESP_LOG_WARN`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
|
||||
#define ESP_EARLY_LOGW( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_WARN, W, ##__VA_ARGS__)
|
||||
/// macro to output logs in startup code at ``ESP_LOG_INFO`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
|
||||
#define ESP_EARLY_LOGI( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_INFO, I, ##__VA_ARGS__)
|
||||
/// macro to output logs in startup code at ``ESP_LOG_DEBUG`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
|
||||
#define ESP_EARLY_LOGD( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_DEBUG, D, ##__VA_ARGS__)
|
||||
/// macro to output logs in startup code at ``ESP_LOG_VERBOSE`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
|
||||
#define ESP_EARLY_LOGV( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_VERBOSE, V, ##__VA_ARGS__)
|
||||
|
||||
#define ESP_LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) do { \
|
||||
if (LOG_LOCAL_LEVEL >= log_level) { \
|
||||
ets_printf(LOG_FORMAT(log_tag_letter, format), esp_log_timestamp(), tag, ##__VA_ARGS__); \
|
||||
}} while(0)
|
||||
|
||||
#ifndef BOOTLOADER_BUILD
|
||||
#define ESP_LOGE( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
|
||||
#define ESP_LOGW( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
|
||||
#define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
|
||||
#define ESP_LOGD( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
|
||||
#define ESP_LOGV( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, tag, format, ##__VA_ARGS__)
|
||||
#else
|
||||
/**
|
||||
* macro to output logs at ESP_LOG_ERROR level.
|
||||
*
|
||||
* @param tag tag of the log, which can be used to change the log level by ``esp_log_level_set`` at runtime.
|
||||
*
|
||||
* @see ``printf``
|
||||
*/
|
||||
#define ESP_LOGE( tag, format, ... ) ESP_EARLY_LOGE(tag, format, ##__VA_ARGS__)
|
||||
/// macro to output logs at ``ESP_LOG_WARN`` level. @see ``ESP_LOGE``
|
||||
#define ESP_LOGW( tag, format, ... ) ESP_EARLY_LOGW(tag, format, ##__VA_ARGS__)
|
||||
/// macro to output logs at ``ESP_LOG_INFO`` level. @see ``ESP_LOGE``
|
||||
#define ESP_LOGI( tag, format, ... ) ESP_EARLY_LOGI(tag, format, ##__VA_ARGS__)
|
||||
/// macro to output logs at ``ESP_LOG_DEBUG`` level. @see ``ESP_LOGE``
|
||||
#define ESP_LOGD( tag, format, ... ) ESP_EARLY_LOGD(tag, format, ##__VA_ARGS__)
|
||||
/// macro to output logs at ``ESP_LOG_VERBOSE`` level. @see ``ESP_LOGE``
|
||||
#define ESP_LOGV( tag, format, ... ) ESP_EARLY_LOGV(tag, format, ##__VA_ARGS__)
|
||||
#endif // BOOTLOADER_BUILD
|
||||
|
||||
/** runtime macro to output logs at a specified level.
|
||||
*
|
||||
* @param tag tag of the log, which can be used to change the log level by ``esp_log_level_set`` at runtime.
|
||||
* @param level level of the output log.
|
||||
* @param format format of the output log. see ``printf``
|
||||
* @param ... variables to be replaced into the log. see ``printf``
|
||||
*
|
||||
* @see ``printf``
|
||||
*/
|
||||
#define ESP_LOG_LEVEL(level, tag, format, ...) do { \
|
||||
if (level==ESP_LOG_ERROR ) { \
|
||||
esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_DEBUG ) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_VERBOSE ) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
|
||||
else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
|
||||
} while(0)
|
||||
|
||||
/** runtime macro to output logs at a specified level. Also check the level with ``LOG_LOCAL_LEVEL``.
|
||||
*
|
||||
* @see ``printf``, ``ESP_LOG_LEVEL``
|
||||
*/
|
||||
#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do { \
|
||||
if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#else /* RIOT_VERSION */
|
||||
|
||||
#include "esp_common.h"
|
||||
|
||||
#ifndef LOG_LOCAL_LEVEL
|
||||
#define LOG_LOCAL_LEVEL (esp_log_level_t)LOG_LEVEL
|
||||
#endif
|
||||
|
||||
#define ESP_LOG_LEVEL(level, tag, format, ...) \
|
||||
do { \
|
||||
if ((esp_log_level_t)level==ESP_LOG_ERROR ) { \
|
||||
LOG_TAG(level, E, tag, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
else if ((esp_log_level_t)level==ESP_LOG_WARN ) { \
|
||||
LOG_TAG(level, W, tag, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
else if ((esp_log_level_t)level==ESP_LOG_INFO ) { \
|
||||
LOG_TAG(level, I, tag, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
else if ((esp_log_level_t)level==ESP_LOG_DEBUG ) { \
|
||||
LOG_TAG(level, D, tag, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
else if ((esp_log_level_t)level==ESP_LOG_VERBOSE ) { \
|
||||
LOG_TAG(level, V, tag, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) \
|
||||
do { \
|
||||
if ( LOG_LOCAL_LEVEL >= level ) { \
|
||||
ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#endif /* RIOT_VERSION */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LOG_ESP_LOG_H */
|
7
cpu/esp8266/vendor/esp-idf/nvs_flash/.gitignore
vendored
Normal file
7
cpu/esp8266/vendor/esp-idf/nvs_flash/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
test_nvs_host/test_nvs
|
||||
test_nvs_host/coverage_report
|
||||
test_nvs_host/coverage.info
|
||||
**/*.gcno
|
||||
**/*.gcda
|
||||
**/*.gcov
|
||||
**/*.o
|
9
cpu/esp8266/vendor/esp-idf/nvs_flash/Makefile
vendored
Normal file
9
cpu/esp8266/vendor/esp-idf/nvs_flash/Makefile
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MODULE=esp_idf_nvs_flash
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
CFLAGS += -DESP_PLATFORM
|
||||
CXXFLAGS += -std=c++11
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/log/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/nvs_flash/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/spi_flash/include
|
8
cpu/esp8266/vendor/esp-idf/nvs_flash/src/Makefile
vendored
Normal file
8
cpu/esp8266/vendor/esp-idf/nvs_flash/src/Makefile
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
MODULE=esp_idf_nvs_flash
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
CFLAGS += -DESP_PLATFORM -DNVS_CRC_HEADER_FILE=\"crc.h\"
|
||||
CXXFLAGS += -std=c++11
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/nvs_flash/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/util/include
|
79
cpu/esp8266/vendor/esp-idf/nvs_flash/src/compressed_enum_table.hpp
vendored
Normal file
79
cpu/esp8266/vendor/esp-idf/nvs_flash/src/compressed_enum_table.hpp
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
// Copyright 2015-2016 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 compressed_enum_table_h
|
||||
#define compressed_enum_table_h
|
||||
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
template<typename Tenum, size_t Nbits, size_t Nitems>
|
||||
class CompressedEnumTable
|
||||
{
|
||||
public:
|
||||
uint32_t* data()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
const uint32_t* data() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
Tenum get(size_t index) const
|
||||
{
|
||||
assert(index >= 0 && index < Nitems);
|
||||
size_t wordIndex = index / ITEMS_PER_WORD;
|
||||
size_t offset = (index % ITEMS_PER_WORD) * Nbits;
|
||||
|
||||
return static_cast<Tenum>((mData[wordIndex] >> offset) & VALUE_MASK);
|
||||
}
|
||||
|
||||
void set(size_t index, Tenum val)
|
||||
{
|
||||
assert(index >= 0 && index < Nitems);
|
||||
size_t wordIndex = index / ITEMS_PER_WORD;
|
||||
size_t offset = (index % ITEMS_PER_WORD) * Nbits;
|
||||
|
||||
uint32_t v = static_cast<uint32_t>(val) << offset;
|
||||
mData[wordIndex] = (mData[wordIndex] & ~(VALUE_MASK << offset)) | v;
|
||||
}
|
||||
|
||||
static constexpr size_t getWordIndex(size_t index)
|
||||
{
|
||||
return index / ITEMS_PER_WORD;
|
||||
}
|
||||
|
||||
static constexpr size_t byteSize()
|
||||
{
|
||||
return WORD_COUNT * 4;
|
||||
}
|
||||
|
||||
static constexpr size_t count()
|
||||
{
|
||||
return Nitems;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
static_assert(32 % Nbits == 0, "Nbits must divide 32");
|
||||
static const size_t ITEMS_PER_WORD = 32 / Nbits;
|
||||
static const size_t WORD_COUNT = ( Nbits * Nitems + 31 ) / 32;
|
||||
static const uint32_t VALUE_MASK = (1 << Nbits) - 1;
|
||||
uint32_t mData[WORD_COUNT];
|
||||
};
|
||||
|
||||
#endif /* compressed_enum_table_h */
|
248
cpu/esp8266/vendor/esp-idf/nvs_flash/src/intrusive_list.h
vendored
Normal file
248
cpu/esp8266/vendor/esp-idf/nvs_flash/src/intrusive_list.h
vendored
Normal file
@ -0,0 +1,248 @@
|
||||
// Copyright 2015-2016 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 intrusive_list_h
|
||||
#define intrusive_list_h
|
||||
|
||||
#include <cassert>
|
||||
|
||||
template <typename T>
|
||||
class intrusive_list;
|
||||
|
||||
template <typename T>
|
||||
class intrusive_list_node
|
||||
{
|
||||
protected:
|
||||
friend class intrusive_list<T>;
|
||||
T* mPrev = nullptr;
|
||||
T* mNext = nullptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class intrusive_list
|
||||
{
|
||||
typedef intrusive_list_node<T> TNode;
|
||||
static_assert(std::is_base_of<TNode, T>::value, "");
|
||||
|
||||
public:
|
||||
|
||||
class iterator : public std::iterator<std::forward_iterator_tag, T>
|
||||
{
|
||||
public:
|
||||
|
||||
iterator() : mPos(nullptr) {}
|
||||
|
||||
iterator(T* pos) : mPos(pos) {}
|
||||
|
||||
iterator operator++(int)
|
||||
{
|
||||
auto result = *this;
|
||||
mPos = mPos->mNext;
|
||||
return result;
|
||||
}
|
||||
|
||||
iterator operator--(int)
|
||||
{
|
||||
auto result = *this;
|
||||
mPos = mPos->mPrev;
|
||||
return result;
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
mPos = mPos->mNext;
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator& operator--()
|
||||
{
|
||||
mPos = mPos->mPrev;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const iterator& other) const
|
||||
{
|
||||
return mPos == other.mPos;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
T& operator*()
|
||||
{
|
||||
return *mPos;
|
||||
}
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
return *mPos;
|
||||
}
|
||||
|
||||
T* operator->()
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
|
||||
const T* operator->() const
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
|
||||
operator const T*() const
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
T* mPos;
|
||||
};
|
||||
|
||||
void push_back(T* node)
|
||||
{
|
||||
if (mLast) {
|
||||
mLast->mNext = node;
|
||||
}
|
||||
node->mPrev = mLast;
|
||||
node->mNext = nullptr;
|
||||
mLast = node;
|
||||
if (mFirst == nullptr) {
|
||||
mFirst = node;
|
||||
}
|
||||
++mSize;
|
||||
}
|
||||
|
||||
void push_front(T* node)
|
||||
{
|
||||
node->mPrev = nullptr;
|
||||
node->mNext = mFirst;
|
||||
if (mFirst) {
|
||||
mFirst->mPrev = node;
|
||||
}
|
||||
mFirst = node;
|
||||
if (mLast == nullptr) {
|
||||
mLast = node;
|
||||
}
|
||||
++mSize;
|
||||
}
|
||||
|
||||
T& back()
|
||||
{
|
||||
return *mLast;
|
||||
}
|
||||
|
||||
const T& back() const
|
||||
{
|
||||
return *mLast;
|
||||
}
|
||||
|
||||
T& front()
|
||||
{
|
||||
return *mFirst;
|
||||
}
|
||||
|
||||
const T& front() const
|
||||
{
|
||||
return *mFirst;
|
||||
}
|
||||
|
||||
void pop_front()
|
||||
{
|
||||
erase(mFirst);
|
||||
}
|
||||
|
||||
void pop_back()
|
||||
{
|
||||
erase(mLast);
|
||||
}
|
||||
|
||||
void insert(iterator next, T* node)
|
||||
{
|
||||
if (static_cast<T*>(next) == nullptr) {
|
||||
push_back(node);
|
||||
} else {
|
||||
auto prev = next->mPrev;
|
||||
if (!prev) {
|
||||
push_front(node);
|
||||
} else {
|
||||
prev->mNext = node;
|
||||
next->mPrev = node;
|
||||
node->mNext = next;
|
||||
node->mPrev = &(*prev);
|
||||
++mSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void erase(iterator it)
|
||||
{
|
||||
auto prev = it->mPrev;
|
||||
auto next = it->mNext;
|
||||
|
||||
if (prev) {
|
||||
prev->mNext = next;
|
||||
} else {
|
||||
mFirst = next;
|
||||
}
|
||||
if (next) {
|
||||
next->mPrev = prev;
|
||||
} else {
|
||||
mLast = prev;
|
||||
}
|
||||
--mSize;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(mFirst);
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return iterator(nullptr);
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return mSize == 0;
|
||||
}
|
||||
|
||||
|
||||
void clear()
|
||||
{
|
||||
while (mFirst) {
|
||||
erase(mFirst);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
T* mFirst = nullptr;
|
||||
T* mLast = nullptr;
|
||||
size_t mSize = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* intrusive_list_h */
|
25
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs.hpp
vendored
Normal file
25
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs.hpp
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2015-2016 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 nvs_hpp
|
||||
#define nvs_hpp
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include "nvs.h"
|
||||
#include "nvs_types.hpp"
|
||||
#include "nvs_page.hpp"
|
||||
#include "nvs_pagemanager.hpp"
|
||||
#include "nvs_storage.hpp"
|
||||
|
||||
#endif /* nvs_hpp */
|
460
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_api.cpp
vendored
Normal file
460
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_api.cpp
vendored
Normal file
@ -0,0 +1,460 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "nvs.hpp"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs_storage.hpp"
|
||||
#include "intrusive_list.h"
|
||||
#include "nvs_platform.hpp"
|
||||
#include "esp_partition.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
// Uncomment this line to force output from this module
|
||||
// #define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#include "esp_log.h"
|
||||
static const char* TAG = "nvs";
|
||||
#else
|
||||
#define ESP_LOGD(...)
|
||||
#endif
|
||||
|
||||
class HandleEntry : public intrusive_list_node<HandleEntry>
|
||||
{
|
||||
static uint32_t s_nvs_next_handle;
|
||||
public:
|
||||
HandleEntry() {}
|
||||
|
||||
HandleEntry(bool readOnly, uint8_t nsIndex, nvs::Storage* StoragePtr) :
|
||||
mHandle(++s_nvs_next_handle), // Begin the handle value with 1
|
||||
mReadOnly(readOnly),
|
||||
mNsIndex(nsIndex),
|
||||
mStoragePtr(StoragePtr)
|
||||
{
|
||||
}
|
||||
|
||||
nvs_handle mHandle;
|
||||
uint8_t mReadOnly;
|
||||
uint8_t mNsIndex;
|
||||
nvs::Storage* mStoragePtr;
|
||||
};
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
SemaphoreHandle_t nvs::Lock::mSemaphore = NULL;
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace nvs;
|
||||
|
||||
static intrusive_list<HandleEntry> s_nvs_handles;
|
||||
uint32_t HandleEntry::s_nvs_next_handle;
|
||||
static intrusive_list<nvs::Storage> s_nvs_storage_list;
|
||||
|
||||
static nvs::Storage* lookup_storage_from_name(const char *name)
|
||||
{
|
||||
auto it = find_if(begin(s_nvs_storage_list), end(s_nvs_storage_list), [=](Storage& e) -> bool {
|
||||
return (strcmp(e.getPartName(), name) == 0);
|
||||
});
|
||||
|
||||
if (it == end(s_nvs_storage_list)) {
|
||||
return NULL;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
extern "C" void nvs_dump(const char *partName)
|
||||
{
|
||||
Lock lock;
|
||||
nvs::Storage* pStorage;
|
||||
|
||||
pStorage = lookup_storage_from_name(partName);
|
||||
if (pStorage == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
pStorage->debugDump();
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_flash_init_custom(const char *partName, uint32_t baseSector, uint32_t sectorCount)
|
||||
{
|
||||
ESP_LOGD(TAG, "nvs_flash_init_custom partition=%s start=%d count=%d", partName, baseSector, sectorCount);
|
||||
nvs::Storage* new_storage = NULL;
|
||||
nvs::Storage* storage = lookup_storage_from_name(partName);
|
||||
if (storage == NULL) {
|
||||
new_storage = new nvs::Storage((const char *)partName);
|
||||
storage = new_storage;
|
||||
}
|
||||
|
||||
esp_err_t err = storage->init(baseSector, sectorCount);
|
||||
if (new_storage != NULL) {
|
||||
if (err == ESP_OK) {
|
||||
s_nvs_storage_list.push_back(new_storage);
|
||||
} else {
|
||||
delete new_storage;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
extern "C" esp_err_t nvs_flash_init_partition(const char *part_name)
|
||||
{
|
||||
Lock::init();
|
||||
Lock lock;
|
||||
nvs::Storage* mStorage;
|
||||
|
||||
mStorage = lookup_storage_from_name(part_name);
|
||||
if (mStorage) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const esp_partition_t* partition = esp_partition_find_first(
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
|
||||
if (partition == NULL) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
return nvs_flash_init_custom(part_name, partition->address / SPI_FLASH_SEC_SIZE,
|
||||
partition->size / SPI_FLASH_SEC_SIZE);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_flash_init(void)
|
||||
{
|
||||
return nvs_flash_init_partition(NVS_DEFAULT_PART_NAME);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_flash_deinit_partition(const char* partition_name)
|
||||
{
|
||||
Lock::init();
|
||||
Lock lock;
|
||||
|
||||
nvs::Storage* storage = lookup_storage_from_name(partition_name);
|
||||
if (!storage) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
/* Clean up handles related to the storage being deinitialized */
|
||||
auto it = s_nvs_handles.begin();
|
||||
auto next = it;
|
||||
while(it != s_nvs_handles.end()) {
|
||||
next++;
|
||||
if (it->mStoragePtr == storage) {
|
||||
ESP_LOGD(TAG, "Deleting handle %d (ns=%d) related to partition \"%s\" (missing call to nvs_close?)",
|
||||
it->mHandle, it->mNsIndex, partition_name);
|
||||
s_nvs_handles.erase(it);
|
||||
delete static_cast<HandleEntry*>(it);
|
||||
}
|
||||
it = next;
|
||||
}
|
||||
|
||||
/* Finally delete the storage itself */
|
||||
s_nvs_storage_list.erase(storage);
|
||||
delete storage;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_flash_deinit(void)
|
||||
{
|
||||
return nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_flash_erase_partition(const char *part_name)
|
||||
{
|
||||
const esp_partition_t* partition = esp_partition_find_first(
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
|
||||
if (partition == NULL) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
return esp_partition_erase_range(partition, 0, partition->size);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_flash_erase()
|
||||
{
|
||||
return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
|
||||
{
|
||||
auto it = find_if(begin(s_nvs_handles), end(s_nvs_handles), [=](HandleEntry& e) -> bool {
|
||||
return e.mHandle == handle;
|
||||
});
|
||||
if (it == end(s_nvs_handles)) {
|
||||
return ESP_ERR_NVS_INVALID_HANDLE;
|
||||
}
|
||||
entry = *it;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s %d", __func__, name, open_mode);
|
||||
uint8_t nsIndex;
|
||||
nvs::Storage* sHandle;
|
||||
|
||||
sHandle = lookup_storage_from_name(part_name);
|
||||
if (sHandle == NULL) {
|
||||
return ESP_ERR_NVS_PART_NOT_FOUND;
|
||||
}
|
||||
|
||||
esp_err_t err = sHandle->createOrOpenNamespace(name, open_mode == NVS_READWRITE, nsIndex);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
HandleEntry *handle_entry = new HandleEntry(open_mode==NVS_READONLY, nsIndex, sHandle);
|
||||
s_nvs_handles.push_back(handle_entry);
|
||||
|
||||
*out_handle = handle_entry->mHandle;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
|
||||
{
|
||||
if (s_nvs_storage_list.size() == 0) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
return nvs_open_from_partition(NVS_DEFAULT_PART_NAME, name, open_mode, out_handle);
|
||||
}
|
||||
|
||||
extern "C" void nvs_close(nvs_handle handle)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %d", __func__, handle);
|
||||
auto it = find_if(begin(s_nvs_handles), end(s_nvs_handles), [=](HandleEntry& e) -> bool {
|
||||
return e.mHandle == handle;
|
||||
});
|
||||
if (it == end(s_nvs_handles)) {
|
||||
return;
|
||||
}
|
||||
s_nvs_handles.erase(it);
|
||||
delete static_cast<HandleEntry*>(it);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_erase_key(nvs_handle handle, const char* key)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s\r\n", __func__, key);
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
if (entry.mReadOnly) {
|
||||
return ESP_ERR_NVS_READ_ONLY;
|
||||
}
|
||||
return entry.mStoragePtr->eraseItem(entry.mNsIndex, key);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_erase_all(nvs_handle handle)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s\r\n", __func__);
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
if (entry.mReadOnly) {
|
||||
return ESP_ERR_NVS_READ_ONLY;
|
||||
}
|
||||
return entry.mStoragePtr->eraseNamespace(entry.mNsIndex);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static esp_err_t nvs_set(nvs_handle handle, const char* key, T value)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s %d %d", __func__, key, sizeof(T), (uint32_t) value);
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
if (entry.mReadOnly) {
|
||||
return ESP_ERR_NVS_READ_ONLY;
|
||||
}
|
||||
return entry.mStoragePtr->writeItem(entry.mNsIndex, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_i8 (nvs_handle handle, const char* key, int8_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_u8 (nvs_handle handle, const char* key, uint8_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_i16 (nvs_handle handle, const char* key, int16_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_u16 (nvs_handle handle, const char* key, uint16_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_i32 (nvs_handle handle, const char* key, int32_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_u32 (nvs_handle handle, const char* key, uint32_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_i64 (nvs_handle handle, const char* key, int64_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_u64 (nvs_handle handle, const char* key, uint64_t value)
|
||||
{
|
||||
return nvs_set(handle, key, value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_commit(nvs_handle handle)
|
||||
{
|
||||
Lock lock;
|
||||
// no-op for now, to be used when intermediate cache is added
|
||||
HandleEntry entry;
|
||||
return nvs_find_ns_handle(handle, entry);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_str(nvs_handle handle, const char* key, const char* value)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s %s", __func__, key, value);
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
return entry.mStoragePtr->writeItem(entry.mNsIndex, nvs::ItemType::SZ, key, value, strlen(value) + 1);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s %d", __func__, key, length);
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
return entry.mStoragePtr->writeItem(entry.mNsIndex, nvs::ItemType::BLOB, key, value, length);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
static esp_err_t nvs_get(nvs_handle handle, const char* key, T* out_value)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s %d", __func__, key, sizeof(T));
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
return entry.mStoragePtr->readItem(entry.mNsIndex, key, *out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_i8 (nvs_handle handle, const char* key, int8_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_u8 (nvs_handle handle, const char* key, uint8_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_i16 (nvs_handle handle, const char* key, int16_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_u16 (nvs_handle handle, const char* key, uint16_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_i32 (nvs_handle handle, const char* key, int32_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_u32 (nvs_handle handle, const char* key, uint32_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_i64 (nvs_handle handle, const char* key, int64_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value)
|
||||
{
|
||||
return nvs_get(handle, key, out_value);
|
||||
}
|
||||
|
||||
static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, const char* key, void* out_value, size_t* length)
|
||||
{
|
||||
Lock lock;
|
||||
ESP_LOGD(TAG, "%s %s", __func__, key);
|
||||
HandleEntry entry;
|
||||
auto err = nvs_find_ns_handle(handle, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
size_t dataSize;
|
||||
err = entry.mStoragePtr->getItemDataSize(entry.mNsIndex, type, key, dataSize);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (length == nullptr) {
|
||||
return ESP_ERR_NVS_INVALID_LENGTH;
|
||||
} else if (out_value == nullptr) {
|
||||
*length = dataSize;
|
||||
return ESP_OK;
|
||||
} else if (*length < dataSize) {
|
||||
*length = dataSize;
|
||||
return ESP_ERR_NVS_INVALID_LENGTH;
|
||||
}
|
||||
|
||||
*length = dataSize;
|
||||
return entry.mStoragePtr->readItem(entry.mNsIndex, type, key, out_value, dataSize);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_str(nvs_handle handle, const char* key, char* out_value, size_t* length)
|
||||
{
|
||||
return nvs_get_str_or_blob(handle, nvs::ItemType::SZ, key, out_value, length);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size_t* length)
|
||||
{
|
||||
return nvs_get_str_or_blob(handle, nvs::ItemType::BLOB, key, out_value, length);
|
||||
}
|
||||
|
107
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_item_hash_list.cpp
vendored
Normal file
107
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_item_hash_list.cpp
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "nvs_item_hash_list.hpp"
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
HashList::HashList()
|
||||
{
|
||||
}
|
||||
|
||||
void HashList::clear()
|
||||
{
|
||||
for (auto it = mBlockList.begin(); it != mBlockList.end();) {
|
||||
auto tmp = it;
|
||||
++it;
|
||||
mBlockList.erase(tmp);
|
||||
delete static_cast<HashListBlock*>(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
HashList::~HashList()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
HashList::HashListBlock::HashListBlock()
|
||||
{
|
||||
static_assert(sizeof(HashListBlock) == HashListBlock::BYTE_SIZE,
|
||||
"cache block size calculation incorrect");
|
||||
}
|
||||
|
||||
void HashList::insert(const Item& item, size_t index)
|
||||
{
|
||||
const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff;
|
||||
// add entry to the end of last block if possible
|
||||
if (mBlockList.size()) {
|
||||
auto& block = mBlockList.back();
|
||||
if (block.mCount < HashListBlock::ENTRY_COUNT) {
|
||||
block.mNodes[block.mCount++] = HashListNode(hash_24, index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if the above failed, create a new block and add entry to it
|
||||
HashListBlock* newBlock = new HashListBlock;
|
||||
mBlockList.push_back(newBlock);
|
||||
newBlock->mNodes[0] = HashListNode(hash_24, index);
|
||||
newBlock->mCount++;
|
||||
}
|
||||
|
||||
void HashList::erase(size_t index, bool itemShouldExist)
|
||||
{
|
||||
for (auto it = mBlockList.begin(); it != mBlockList.end();) {
|
||||
bool haveEntries = false;
|
||||
for (size_t i = 0; i < it->mCount; ++i) {
|
||||
if (it->mNodes[i].mIndex == index) {
|
||||
it->mNodes[i].mIndex = 0xff;
|
||||
return;
|
||||
}
|
||||
if (it->mNodes[i].mIndex != 0xff) {
|
||||
haveEntries = true;
|
||||
}
|
||||
}
|
||||
if (!haveEntries) {
|
||||
auto tmp = it;
|
||||
++it;
|
||||
mBlockList.erase(tmp);
|
||||
delete static_cast<HashListBlock*>(tmp);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
if (itemShouldExist) {
|
||||
assert(false && "item should have been present in cache");
|
||||
}
|
||||
}
|
||||
|
||||
size_t HashList::find(size_t start, const Item& item)
|
||||
{
|
||||
const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff;
|
||||
for (auto it = mBlockList.begin(); it != mBlockList.end(); ++it) {
|
||||
for (size_t index = 0; index < it->mCount; ++index) {
|
||||
HashListNode& e = it->mNodes[index];
|
||||
if (e.mIndex >= start &&
|
||||
e.mHash == hash_24 &&
|
||||
e.mIndex != 0xff) {
|
||||
return e.mIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
|
||||
} // namespace nvs
|
74
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_item_hash_list.hpp
vendored
Normal file
74
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_item_hash_list.hpp
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
// Copyright 2015-2016 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 nvs_item_hash_list_h
|
||||
#define nvs_item_hash_list_h
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_types.hpp"
|
||||
#include "intrusive_list.h"
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
class HashList
|
||||
{
|
||||
public:
|
||||
HashList();
|
||||
~HashList();
|
||||
|
||||
void insert(const Item& item, size_t index);
|
||||
void erase(const size_t index, bool itemShouldExist=true);
|
||||
size_t find(size_t start, const Item& item);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
HashList(const HashList& other);
|
||||
const HashList& operator= (const HashList& rhs);
|
||||
|
||||
protected:
|
||||
|
||||
struct HashListNode {
|
||||
HashListNode() :
|
||||
mIndex(0xff), mHash(0)
|
||||
{
|
||||
}
|
||||
|
||||
HashListNode(uint32_t hash, size_t index) :
|
||||
mIndex((uint32_t) index), mHash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t mIndex : 8;
|
||||
uint32_t mHash : 24;
|
||||
};
|
||||
|
||||
struct HashListBlock : public intrusive_list_node<HashList::HashListBlock> {
|
||||
HashListBlock();
|
||||
|
||||
static const size_t BYTE_SIZE = 128;
|
||||
static const size_t ENTRY_COUNT = (BYTE_SIZE - sizeof(intrusive_list_node<HashListBlock>) - sizeof(size_t)) / 4;
|
||||
|
||||
size_t mCount = 0;
|
||||
HashListNode mNodes[ENTRY_COUNT];
|
||||
};
|
||||
|
||||
typedef intrusive_list<HashListBlock> TBlockList;
|
||||
TBlockList mBlockList;
|
||||
}; // class HashList
|
||||
|
||||
} // namespace nvs
|
||||
|
||||
|
||||
#endif /* nvs_item_hash_list_h */
|
893
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_page.cpp
vendored
Normal file
893
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_page.cpp
vendored
Normal file
@ -0,0 +1,893 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "nvs_page.hpp"
|
||||
#if defined(ESP_PLATFORM)
|
||||
#if defined(NVS_CRC_HEADER_FILE)
|
||||
#include NVS_CRC_HEADER_FILE
|
||||
#else
|
||||
#include <rom/crc.h>
|
||||
#endif
|
||||
#else
|
||||
#include "crc.h"
|
||||
#endif
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
uint32_t Page::Header::calculateCrc32()
|
||||
{
|
||||
return crc32_le(0xffffffff,
|
||||
reinterpret_cast<uint8_t*>(this) + offsetof(Header, mSeqNumber),
|
||||
offsetof(Header, mCrc32) - offsetof(Header, mSeqNumber));
|
||||
}
|
||||
|
||||
esp_err_t Page::load(uint32_t sectorNumber)
|
||||
{
|
||||
mBaseAddress = sectorNumber * SEC_SIZE;
|
||||
mUsedEntryCount = 0;
|
||||
mErasedEntryCount = 0;
|
||||
|
||||
Header header;
|
||||
auto rc = spi_flash_read(mBaseAddress, &header, sizeof(header));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
if (header.mState == PageState::UNINITIALIZED) {
|
||||
mState = header.mState;
|
||||
// check if the whole page is really empty
|
||||
// reading the whole page takes ~40 times less than erasing it
|
||||
uint32_t line[8];
|
||||
for (uint32_t i = 0; i < SPI_FLASH_SEC_SIZE; i += sizeof(line)) {
|
||||
rc = spi_flash_read(mBaseAddress + i, line, sizeof(line));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
if (std::any_of(line, line + 4, [](uint32_t val) -> bool { return val != 0xffffffff; })) {
|
||||
// page isn't as empty after all, mark it as corrupted
|
||||
mState = PageState::CORRUPT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (header.mCrc32 != header.calculateCrc32()) {
|
||||
header.mState = PageState::CORRUPT;
|
||||
} else {
|
||||
mState = header.mState;
|
||||
mSeqNumber = header.mSeqNumber;
|
||||
}
|
||||
|
||||
switch (mState) {
|
||||
case PageState::UNINITIALIZED:
|
||||
break;
|
||||
|
||||
case PageState::FULL:
|
||||
case PageState::ACTIVE:
|
||||
case PageState::FREEING:
|
||||
mLoadEntryTable();
|
||||
break;
|
||||
|
||||
default:
|
||||
mState = PageState::CORRUPT;
|
||||
break;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::writeEntry(const Item& item)
|
||||
{
|
||||
auto rc = spi_flash_write(getEntryAddress(mNextFreeEntry), &item, sizeof(item));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
|
||||
auto err = alterEntryState(mNextFreeEntry, EntryState::WRITTEN);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (mFirstUsedEntry == INVALID_ENTRY) {
|
||||
mFirstUsedEntry = mNextFreeEntry;
|
||||
}
|
||||
|
||||
++mUsedEntryCount;
|
||||
++mNextFreeEntry;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::writeEntryData(const uint8_t* data, size_t size)
|
||||
{
|
||||
assert(size % ENTRY_SIZE == 0);
|
||||
assert(mNextFreeEntry != INVALID_ENTRY);
|
||||
assert(mFirstUsedEntry != INVALID_ENTRY);
|
||||
const uint16_t count = size / ENTRY_SIZE;
|
||||
|
||||
const uint8_t* buf = data;
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/* On the ESP32, data can come from DROM, which is not accessible by spi_flash_write
|
||||
* function. To work around this, we copy the data to heap if it came from DROM.
|
||||
* Hopefully this won't happen very often in practice. For data from DRAM, we should
|
||||
* still be able to write it to flash directly.
|
||||
* TODO: figure out how to make this platform-specific check nicer (probably by introducing
|
||||
* a platform-specific flash layer).
|
||||
*/
|
||||
if ((uint32_t) data < 0x3ff00000) {
|
||||
buf = (uint8_t*) malloc(size);
|
||||
if (!buf) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
memcpy((void*)buf, data, size);
|
||||
}
|
||||
#endif //ESP_PLATFORM
|
||||
auto rc = spi_flash_write(getEntryAddress(mNextFreeEntry), buf, size);
|
||||
#ifdef ESP_PLATFORM
|
||||
if (buf != data) {
|
||||
free((void*)buf);
|
||||
}
|
||||
#endif //ESP_PLATFORM
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
auto err = alterEntryRangeState(mNextFreeEntry, mNextFreeEntry + count, EntryState::WRITTEN);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
mUsedEntryCount += count;
|
||||
mNextFreeEntry += count;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, const void* data, size_t dataSize)
|
||||
{
|
||||
Item item;
|
||||
esp_err_t err;
|
||||
|
||||
if (mState == PageState::INVALID) {
|
||||
return ESP_ERR_NVS_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (mState == PageState::UNINITIALIZED) {
|
||||
err = initialize();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
if (mState == PageState::FULL) {
|
||||
return ESP_ERR_NVS_PAGE_FULL;
|
||||
}
|
||||
|
||||
const size_t keySize = strlen(key);
|
||||
if (keySize > Item::MAX_KEY_LENGTH) {
|
||||
return ESP_ERR_NVS_KEY_TOO_LONG;
|
||||
}
|
||||
|
||||
if (dataSize > Page::BLOB_MAX_SIZE) {
|
||||
return ESP_ERR_NVS_VALUE_TOO_LONG;
|
||||
}
|
||||
|
||||
size_t totalSize = ENTRY_SIZE;
|
||||
size_t entriesCount = 1;
|
||||
if (datatype == ItemType::SZ || datatype == ItemType::BLOB) {
|
||||
size_t roundedSize = (dataSize + ENTRY_SIZE - 1) & ~(ENTRY_SIZE - 1);
|
||||
totalSize += roundedSize;
|
||||
entriesCount += roundedSize / ENTRY_SIZE;
|
||||
}
|
||||
|
||||
// primitive types should fit into one entry
|
||||
assert(totalSize == ENTRY_SIZE || datatype == ItemType::BLOB || datatype == ItemType::SZ);
|
||||
|
||||
if (mNextFreeEntry == INVALID_ENTRY || mNextFreeEntry + entriesCount > ENTRY_COUNT) {
|
||||
// page will not fit this amount of data
|
||||
return ESP_ERR_NVS_PAGE_FULL;
|
||||
}
|
||||
|
||||
// write first item
|
||||
size_t span = (totalSize + ENTRY_SIZE - 1) / ENTRY_SIZE;
|
||||
item = Item(nsIndex, datatype, span, key);
|
||||
mHashList.insert(item, mNextFreeEntry);
|
||||
|
||||
if (datatype != ItemType::SZ && datatype != ItemType::BLOB) {
|
||||
memcpy(item.data, data, dataSize);
|
||||
item.crc32 = item.calculateCrc32();
|
||||
err = writeEntry(item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
const uint8_t* src = reinterpret_cast<const uint8_t*>(data);
|
||||
item.varLength.dataCrc32 = Item::calculateCrc32(src, dataSize);
|
||||
item.varLength.dataSize = dataSize;
|
||||
item.varLength.reserved2 = 0xffff;
|
||||
item.crc32 = item.calculateCrc32();
|
||||
err = writeEntry(item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
size_t left = dataSize / ENTRY_SIZE * ENTRY_SIZE;
|
||||
if (left > 0) {
|
||||
err = writeEntryData(static_cast<const uint8_t*>(data), left);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
size_t tail = dataSize - left;
|
||||
if (tail > 0) {
|
||||
std::fill_n(item.rawData, ENTRY_SIZE / 4, 0xffffffff);
|
||||
memcpy(item.rawData, static_cast<const uint8_t*>(data) + left, tail);
|
||||
err = writeEntry(item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::readItem(uint8_t nsIndex, ItemType datatype, const char* key, void* data, size_t dataSize)
|
||||
{
|
||||
size_t index = 0;
|
||||
Item item;
|
||||
|
||||
if (mState == PageState::INVALID) {
|
||||
return ESP_ERR_NVS_INVALID_STATE;
|
||||
}
|
||||
|
||||
esp_err_t rc = findItem(nsIndex, datatype, key, index, item);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (datatype != ItemType::SZ && datatype != ItemType::BLOB) {
|
||||
if (dataSize != getAlignmentForType(datatype)) {
|
||||
return ESP_ERR_NVS_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
memcpy(data, item.data, dataSize);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (dataSize < static_cast<size_t>(item.varLength.dataSize)) {
|
||||
return ESP_ERR_NVS_INVALID_LENGTH;
|
||||
}
|
||||
|
||||
uint8_t* dst = reinterpret_cast<uint8_t*>(data);
|
||||
size_t left = item.varLength.dataSize;
|
||||
for (size_t i = index + 1; i < index + item.span; ++i) {
|
||||
Item ditem;
|
||||
rc = readEntry(i, ditem);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
size_t willCopy = ENTRY_SIZE;
|
||||
willCopy = (left < willCopy)?left:willCopy;
|
||||
memcpy(dst, ditem.rawData, willCopy);
|
||||
left -= willCopy;
|
||||
dst += willCopy;
|
||||
}
|
||||
if (Item::calculateCrc32(reinterpret_cast<uint8_t*>(data), item.varLength.dataSize) != item.varLength.dataCrc32) {
|
||||
rc = eraseEntryAndSpan(index);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::eraseItem(uint8_t nsIndex, ItemType datatype, const char* key)
|
||||
{
|
||||
size_t index = 0;
|
||||
Item item;
|
||||
esp_err_t rc = findItem(nsIndex, datatype, key, index, item);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
return eraseEntryAndSpan(index);
|
||||
}
|
||||
|
||||
esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key)
|
||||
{
|
||||
size_t index = 0;
|
||||
Item item;
|
||||
return findItem(nsIndex, datatype, key, index, item);
|
||||
}
|
||||
|
||||
esp_err_t Page::eraseEntryAndSpan(size_t index)
|
||||
{
|
||||
auto state = mEntryTable.get(index);
|
||||
assert(state == EntryState::WRITTEN || state == EntryState::EMPTY);
|
||||
|
||||
size_t span = 1;
|
||||
if (state == EntryState::WRITTEN) {
|
||||
Item item;
|
||||
auto rc = readEntry(index, item);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
if (item.calculateCrc32() != item.crc32) {
|
||||
mHashList.erase(index, false);
|
||||
rc = alterEntryState(index, EntryState::ERASED);
|
||||
--mUsedEntryCount;
|
||||
++mErasedEntryCount;
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
mHashList.erase(index);
|
||||
span = item.span;
|
||||
for (ptrdiff_t i = index + span - 1; i >= static_cast<ptrdiff_t>(index); --i) {
|
||||
if (mEntryTable.get(i) == EntryState::WRITTEN) {
|
||||
--mUsedEntryCount;
|
||||
}
|
||||
++mErasedEntryCount;
|
||||
}
|
||||
if (span == 1) {
|
||||
rc = alterEntryState(index, EntryState::ERASED);
|
||||
} else {
|
||||
rc = alterEntryRangeState(index, index + span, EntryState::ERASED);
|
||||
}
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto rc = alterEntryState(index, EntryState::ERASED);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == mFirstUsedEntry) {
|
||||
updateFirstUsedEntry(index, span);
|
||||
}
|
||||
|
||||
if (index + span > mNextFreeEntry) {
|
||||
mNextFreeEntry = index + span;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void Page::updateFirstUsedEntry(size_t index, size_t span)
|
||||
{
|
||||
assert(index == mFirstUsedEntry);
|
||||
mFirstUsedEntry = INVALID_ENTRY;
|
||||
size_t end = mNextFreeEntry;
|
||||
if (end > ENTRY_COUNT) {
|
||||
end = ENTRY_COUNT;
|
||||
}
|
||||
for (size_t i = index + span; i < end; ++i) {
|
||||
if (mEntryTable.get(i) == EntryState::WRITTEN) {
|
||||
mFirstUsedEntry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t Page::copyItems(Page& other)
|
||||
{
|
||||
if (mFirstUsedEntry == INVALID_ENTRY) {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (other.mState == PageState::UNINITIALIZED) {
|
||||
auto err = other.initialize();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
Item entry;
|
||||
size_t readEntryIndex = mFirstUsedEntry;
|
||||
|
||||
while (readEntryIndex < ENTRY_COUNT) {
|
||||
|
||||
if (mEntryTable.get(readEntryIndex) != EntryState::WRITTEN) {
|
||||
assert(readEntryIndex != mFirstUsedEntry);
|
||||
readEntryIndex++;
|
||||
continue;
|
||||
}
|
||||
auto err = readEntry(readEntryIndex, entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
other.mHashList.insert(entry, other.mNextFreeEntry);
|
||||
err = other.writeEntry(entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
size_t span = entry.span;
|
||||
size_t end = readEntryIndex + span;
|
||||
|
||||
assert(end <= ENTRY_COUNT);
|
||||
|
||||
for (size_t i = readEntryIndex + 1; i < end; ++i) {
|
||||
readEntry(i, entry);
|
||||
err = other.writeEntry(entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
readEntryIndex = end;
|
||||
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::mLoadEntryTable()
|
||||
{
|
||||
// for states where we actually care about data in the page, read entry state table
|
||||
if (mState == PageState::ACTIVE ||
|
||||
mState == PageState::FULL ||
|
||||
mState == PageState::FREEING) {
|
||||
auto rc = spi_flash_read(mBaseAddress + ENTRY_TABLE_OFFSET, mEntryTable.data(),
|
||||
mEntryTable.byteSize());
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
mErasedEntryCount = 0;
|
||||
mUsedEntryCount = 0;
|
||||
for (size_t i = 0; i < ENTRY_COUNT; ++i) {
|
||||
auto s = mEntryTable.get(i);
|
||||
if (s == EntryState::WRITTEN) {
|
||||
if (mFirstUsedEntry == INVALID_ENTRY) {
|
||||
mFirstUsedEntry = i;
|
||||
}
|
||||
++mUsedEntryCount;
|
||||
} else if (s == EntryState::ERASED) {
|
||||
++mErasedEntryCount;
|
||||
}
|
||||
}
|
||||
|
||||
// for PageState::ACTIVE, we may have more data written to this page
|
||||
// as such, we need to figure out where the first unused entry is
|
||||
if (mState == PageState::ACTIVE) {
|
||||
for (size_t i = 0; i < ENTRY_COUNT; ++i) {
|
||||
if (mEntryTable.get(i) == EntryState::EMPTY) {
|
||||
mNextFreeEntry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// however, if power failed after some data was written into the entry.
|
||||
// but before the entry state table was altered, the entry locacted via
|
||||
// entry state table may actually be half-written.
|
||||
// this is easy to check by reading EntryHeader (i.e. first word)
|
||||
while (mNextFreeEntry < ENTRY_COUNT) {
|
||||
uint32_t entryAddress = getEntryAddress(mNextFreeEntry);
|
||||
uint32_t header;
|
||||
auto rc = spi_flash_read(entryAddress, &header, sizeof(header));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
if (header != 0xffffffff) {
|
||||
auto oldState = mEntryTable.get(mNextFreeEntry);
|
||||
auto err = alterEntryState(mNextFreeEntry, EntryState::ERASED);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
++mNextFreeEntry;
|
||||
if (oldState == EntryState::WRITTEN) {
|
||||
--mUsedEntryCount;
|
||||
}
|
||||
++mErasedEntryCount;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check that all variable-length items are written or erased fully
|
||||
Item item;
|
||||
size_t lastItemIndex = INVALID_ENTRY;
|
||||
size_t end = mNextFreeEntry;
|
||||
if (end > ENTRY_COUNT) {
|
||||
end = ENTRY_COUNT;
|
||||
}
|
||||
size_t span;
|
||||
for (size_t i = 0; i < end; i += span) {
|
||||
span = 1;
|
||||
if (mEntryTable.get(i) == EntryState::ERASED) {
|
||||
lastItemIndex = INVALID_ENTRY;
|
||||
continue;
|
||||
}
|
||||
|
||||
lastItemIndex = i;
|
||||
|
||||
auto err = readEntry(i, item);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (item.crc32 != item.calculateCrc32()) {
|
||||
err = eraseEntryAndSpan(i);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
mHashList.insert(item, i);
|
||||
|
||||
// search for potential duplicate item
|
||||
size_t duplicateIndex = mHashList.find(0, item);
|
||||
|
||||
if (item.datatype == ItemType::BLOB || item.datatype == ItemType::SZ) {
|
||||
span = item.span;
|
||||
bool needErase = false;
|
||||
for (size_t j = i; j < i + span; ++j) {
|
||||
if (mEntryTable.get(j) != EntryState::WRITTEN) {
|
||||
needErase = true;
|
||||
lastItemIndex = INVALID_ENTRY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needErase) {
|
||||
eraseEntryAndSpan(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (duplicateIndex < i) {
|
||||
eraseEntryAndSpan(duplicateIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// check that last item is not duplicate
|
||||
if (lastItemIndex != INVALID_ENTRY) {
|
||||
size_t findItemIndex = 0;
|
||||
Item dupItem;
|
||||
if (findItem(item.nsIndex, item.datatype, item.key, findItemIndex, dupItem) == ESP_OK) {
|
||||
if (findItemIndex < lastItemIndex) {
|
||||
auto err = eraseEntryAndSpan(findItemIndex);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mState == PageState::FULL || mState == PageState::FREEING) {
|
||||
// We have already filled mHashList for page in active state.
|
||||
// Do the same for the case when page is in full or freeing state.
|
||||
Item item;
|
||||
for (size_t i = mFirstUsedEntry; i < ENTRY_COUNT; ++i) {
|
||||
if (mEntryTable.get(i) != EntryState::WRITTEN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto err = readEntry(i, item);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (item.crc32 != item.calculateCrc32()) {
|
||||
err = eraseEntryAndSpan(i);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
assert(item.span > 0);
|
||||
|
||||
mHashList.insert(item, i);
|
||||
size_t span = item.span;
|
||||
|
||||
if (item.datatype == ItemType::BLOB || item.datatype == ItemType::SZ) {
|
||||
for (size_t j = i + 1; j < i + span; ++j) {
|
||||
if (mEntryTable.get(j) != EntryState::WRITTEN) {
|
||||
eraseEntryAndSpan(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i += span - 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t Page::initialize()
|
||||
{
|
||||
assert(mState == PageState::UNINITIALIZED);
|
||||
mState = PageState::ACTIVE;
|
||||
Header header;
|
||||
header.mState = mState;
|
||||
header.mSeqNumber = mSeqNumber;
|
||||
header.mCrc32 = header.calculateCrc32();
|
||||
|
||||
auto rc = spi_flash_write(mBaseAddress, &header, sizeof(header));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
|
||||
mNextFreeEntry = 0;
|
||||
std::fill_n(mEntryTable.data(), mEntryTable.byteSize() / sizeof(uint32_t), 0xffffffff);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::alterEntryState(size_t index, EntryState state)
|
||||
{
|
||||
assert(index < ENTRY_COUNT);
|
||||
mEntryTable.set(index, state);
|
||||
size_t wordToWrite = mEntryTable.getWordIndex(index);
|
||||
uint32_t word = mEntryTable.data()[wordToWrite];
|
||||
auto rc = spi_flash_write(mBaseAddress + ENTRY_TABLE_OFFSET + static_cast<uint32_t>(wordToWrite) * 4,
|
||||
&word, sizeof(word));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::alterEntryRangeState(size_t begin, size_t end, EntryState state)
|
||||
{
|
||||
assert(end <= ENTRY_COUNT);
|
||||
assert(end > begin);
|
||||
size_t wordIndex = mEntryTable.getWordIndex(end - 1);
|
||||
for (ptrdiff_t i = end - 1; i >= static_cast<ptrdiff_t>(begin); --i) {
|
||||
mEntryTable.set(i, state);
|
||||
size_t nextWordIndex;
|
||||
if (i == static_cast<ptrdiff_t>(begin)) {
|
||||
nextWordIndex = (size_t) -1;
|
||||
} else {
|
||||
nextWordIndex = mEntryTable.getWordIndex(i - 1);
|
||||
}
|
||||
if (nextWordIndex != wordIndex) {
|
||||
uint32_t word = mEntryTable.data()[wordIndex];
|
||||
auto rc = spi_flash_write(mBaseAddress + ENTRY_TABLE_OFFSET + static_cast<uint32_t>(wordIndex) * 4,
|
||||
&word, 4);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
wordIndex = nextWordIndex;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::alterPageState(PageState state)
|
||||
{
|
||||
uint32_t state_val = static_cast<uint32_t>(state);
|
||||
auto rc = spi_flash_write(mBaseAddress, &state_val, sizeof(state));
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
mState = (PageState) state;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::readEntry(size_t index, Item& dst) const
|
||||
{
|
||||
auto rc = spi_flash_read(getEntryAddress(index), &dst, sizeof(dst));
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, size_t &itemIndex, Item& item)
|
||||
{
|
||||
if (mState == PageState::CORRUPT || mState == PageState::INVALID || mState == PageState::UNINITIALIZED) {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
|
||||
size_t findBeginIndex = itemIndex;
|
||||
if (findBeginIndex >= ENTRY_COUNT) {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
|
||||
size_t start = mFirstUsedEntry;
|
||||
if (findBeginIndex > mFirstUsedEntry && findBeginIndex < ENTRY_COUNT) {
|
||||
start = findBeginIndex;
|
||||
}
|
||||
|
||||
size_t end = mNextFreeEntry;
|
||||
if (end > ENTRY_COUNT) {
|
||||
end = ENTRY_COUNT;
|
||||
}
|
||||
|
||||
if (nsIndex != NS_ANY && datatype != ItemType::ANY && key != NULL) {
|
||||
size_t cachedIndex = mHashList.find(start, Item(nsIndex, datatype, 0, key));
|
||||
if (cachedIndex < ENTRY_COUNT) {
|
||||
start = cachedIndex;
|
||||
} else {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
size_t next;
|
||||
for (size_t i = start; i < end; i = next) {
|
||||
next = i + 1;
|
||||
if (mEntryTable.get(i) != EntryState::WRITTEN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto rc = readEntry(i, item);
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
|
||||
auto crc32 = item.calculateCrc32();
|
||||
if (item.crc32 != crc32) {
|
||||
rc = eraseEntryAndSpan(i);
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.datatype == ItemType::BLOB || item.datatype == ItemType::SZ) {
|
||||
next = i + item.span;
|
||||
}
|
||||
|
||||
if (nsIndex != NS_ANY && item.nsIndex != nsIndex) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key != nullptr && strncmp(key, item.key, Item::MAX_KEY_LENGTH) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (datatype != ItemType::ANY && item.datatype != datatype) {
|
||||
return ESP_ERR_NVS_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
itemIndex = i;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
|
||||
esp_err_t Page::getSeqNumber(uint32_t& seqNumber) const
|
||||
{
|
||||
if (mState != PageState::UNINITIALIZED && mState != PageState::INVALID && mState != PageState::CORRUPT) {
|
||||
seqNumber = mSeqNumber;
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t Page::setSeqNumber(uint32_t seqNumber)
|
||||
{
|
||||
if (mState != PageState::UNINITIALIZED) {
|
||||
return ESP_ERR_NVS_INVALID_STATE;
|
||||
}
|
||||
mSeqNumber = seqNumber;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::erase()
|
||||
{
|
||||
auto sector = mBaseAddress / SPI_FLASH_SEC_SIZE;
|
||||
auto rc = spi_flash_erase_sector(sector);
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
}
|
||||
mUsedEntryCount = 0;
|
||||
mErasedEntryCount = 0;
|
||||
mFirstUsedEntry = INVALID_ENTRY;
|
||||
mNextFreeEntry = INVALID_ENTRY;
|
||||
mState = PageState::UNINITIALIZED;
|
||||
mHashList.clear();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Page::markFreeing()
|
||||
{
|
||||
if (mState != PageState::FULL && mState != PageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_INVALID_STATE;
|
||||
}
|
||||
return alterPageState(PageState::FREEING);
|
||||
}
|
||||
|
||||
esp_err_t Page::markFull()
|
||||
{
|
||||
if (mState != PageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_INVALID_STATE;
|
||||
}
|
||||
return alterPageState(PageState::FULL);
|
||||
}
|
||||
|
||||
const char* Page::pageStateToName(PageState ps)
|
||||
{
|
||||
switch (ps) {
|
||||
case PageState::CORRUPT:
|
||||
return "CORRUPT";
|
||||
|
||||
case PageState::ACTIVE:
|
||||
return "ACTIVE";
|
||||
|
||||
case PageState::FREEING:
|
||||
return "FREEING";
|
||||
|
||||
case PageState::FULL:
|
||||
return "FULL";
|
||||
|
||||
case PageState::INVALID:
|
||||
return "INVALID";
|
||||
|
||||
case PageState::UNINITIALIZED:
|
||||
return "UNINITIALIZED";
|
||||
|
||||
default:
|
||||
assert(0 && "invalid state value");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void Page::debugDump() const
|
||||
{
|
||||
printf("state=%x (%s) addr=%x seq=%d\nfirstUsed=%d nextFree=%d used=%d erased=%d\n", (uint32_t) mState, pageStateToName(mState), mBaseAddress, mSeqNumber, static_cast<int>(mFirstUsedEntry), static_cast<int>(mNextFreeEntry), mUsedEntryCount, mErasedEntryCount);
|
||||
size_t skip = 0;
|
||||
for (size_t i = 0; i < ENTRY_COUNT; ++i) {
|
||||
printf("%3d: ", static_cast<int>(i));
|
||||
EntryState state = mEntryTable.get(i);
|
||||
if (state == EntryState::EMPTY) {
|
||||
printf("E\n");
|
||||
} else if (state == EntryState::ERASED) {
|
||||
printf("X\n");
|
||||
} else if (state == EntryState::WRITTEN) {
|
||||
Item item;
|
||||
readEntry(i, item);
|
||||
if (skip == 0) {
|
||||
printf("W ns=%2u type=%2u span=%3u key=\"%s\" len=%d\n", item.nsIndex, static_cast<unsigned>(item.datatype), item.span, item.key, (item.span != 1)?((int)item.varLength.dataSize):-1);
|
||||
if (item.span > 0 && item.span <= ENTRY_COUNT - i) {
|
||||
skip = item.span - 1;
|
||||
} else {
|
||||
skip = 0;
|
||||
}
|
||||
} else {
|
||||
printf("D\n");
|
||||
skip--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nvs
|
221
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_page.hpp
vendored
Normal file
221
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_page.hpp
vendored
Normal file
@ -0,0 +1,221 @@
|
||||
// Copyright 2015-2016 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 nvs_page_hpp
|
||||
#define nvs_page_hpp
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_types.hpp"
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "esp_spi_flash.h"
|
||||
#include "compressed_enum_table.hpp"
|
||||
#include "intrusive_list.h"
|
||||
#include "nvs_item_hash_list.hpp"
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
|
||||
class Page : public intrusive_list_node<Page>
|
||||
{
|
||||
public:
|
||||
static const uint32_t PSB_INIT = 0x1;
|
||||
static const uint32_t PSB_FULL = 0x2;
|
||||
static const uint32_t PSB_FREEING = 0x4;
|
||||
static const uint32_t PSB_CORRUPT = 0x8;
|
||||
|
||||
static const uint32_t ESB_WRITTEN = 0x1;
|
||||
static const uint32_t ESB_ERASED = 0x2;
|
||||
|
||||
static const uint32_t SEC_SIZE = SPI_FLASH_SEC_SIZE;
|
||||
|
||||
static const size_t ENTRY_SIZE = 32;
|
||||
static const size_t ENTRY_COUNT = 126;
|
||||
static const uint32_t INVALID_ENTRY = 0xffffffff;
|
||||
|
||||
static const size_t BLOB_MAX_SIZE = ENTRY_SIZE * (ENTRY_COUNT / 2 - 1);
|
||||
|
||||
static const uint8_t NS_INDEX = 0;
|
||||
static const uint8_t NS_ANY = 255;
|
||||
|
||||
enum class PageState : uint32_t {
|
||||
// All bits set, default state after flash erase. Page has not been initialized yet.
|
||||
UNINITIALIZED = 0xffffffff,
|
||||
|
||||
// Page is initialized, and will accept writes.
|
||||
ACTIVE = UNINITIALIZED & ~PSB_INIT,
|
||||
|
||||
// Page is marked as full and will not accept new writes.
|
||||
FULL = ACTIVE & ~PSB_FULL,
|
||||
|
||||
// Data is being moved from this page to a new one.
|
||||
FREEING = FULL & ~PSB_FREEING,
|
||||
|
||||
// Page was found to be in a corrupt and unrecoverable state.
|
||||
// Instead of being erased immediately, it will be kept for diagnostics and data recovery.
|
||||
// It will be erased once we run out out free pages.
|
||||
CORRUPT = FREEING & ~PSB_CORRUPT,
|
||||
|
||||
// Page object wasn't loaded from flash memory
|
||||
INVALID = 0
|
||||
};
|
||||
|
||||
PageState state() const
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
esp_err_t load(uint32_t sectorNumber);
|
||||
|
||||
esp_err_t getSeqNumber(uint32_t& seqNumber) const;
|
||||
|
||||
esp_err_t setSeqNumber(uint32_t seqNumber);
|
||||
|
||||
esp_err_t writeItem(uint8_t nsIndex, ItemType datatype, const char* key, const void* data, size_t dataSize);
|
||||
|
||||
esp_err_t readItem(uint8_t nsIndex, ItemType datatype, const char* key, void* data, size_t dataSize);
|
||||
|
||||
esp_err_t eraseItem(uint8_t nsIndex, ItemType datatype, const char* key);
|
||||
|
||||
esp_err_t findItem(uint8_t nsIndex, ItemType datatype, const char* key);
|
||||
|
||||
esp_err_t findItem(uint8_t nsIndex, ItemType datatype, const char* key, size_t &itemIndex, Item& item);
|
||||
|
||||
template<typename T>
|
||||
esp_err_t writeItem(uint8_t nsIndex, const char* key, const T& value)
|
||||
{
|
||||
return writeItem(nsIndex, itemTypeOf(value), key, &value, sizeof(value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
esp_err_t readItem(uint8_t nsIndex, const char* key, T& value)
|
||||
{
|
||||
return readItem(nsIndex, itemTypeOf(value), key, &value, sizeof(value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
esp_err_t eraseItem(uint8_t nsIndex, const char* key)
|
||||
{
|
||||
return eraseItem(nsIndex, itemTypeOf<T>(), key);
|
||||
}
|
||||
|
||||
size_t getUsedEntryCount() const
|
||||
{
|
||||
return mUsedEntryCount;
|
||||
}
|
||||
|
||||
size_t getErasedEntryCount() const
|
||||
{
|
||||
return mErasedEntryCount;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t markFull();
|
||||
|
||||
esp_err_t markFreeing();
|
||||
|
||||
esp_err_t copyItems(Page& other);
|
||||
|
||||
esp_err_t erase();
|
||||
|
||||
void debugDump() const;
|
||||
|
||||
protected:
|
||||
|
||||
class Header
|
||||
{
|
||||
public:
|
||||
Header()
|
||||
{
|
||||
std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT32_MAX);
|
||||
}
|
||||
|
||||
PageState mState; // page state
|
||||
uint32_t mSeqNumber; // sequence number of this page
|
||||
uint32_t mReserved[5]; // unused, must be 0xffffffff
|
||||
uint32_t mCrc32; // crc of everything except mState
|
||||
|
||||
uint32_t calculateCrc32();
|
||||
};
|
||||
|
||||
enum class EntryState {
|
||||
EMPTY = 0x3, // 0b11, default state after flash erase
|
||||
WRITTEN = EMPTY & ~ESB_WRITTEN, // entry was written
|
||||
ERASED = WRITTEN & ~ESB_ERASED, // entry was written and then erased
|
||||
INVALID = 0x4 // entry is in inconsistent state (write started but ESB_WRITTEN has not been set yet)
|
||||
};
|
||||
|
||||
esp_err_t mLoadEntryTable();
|
||||
|
||||
esp_err_t initialize();
|
||||
|
||||
esp_err_t alterEntryState(size_t index, EntryState state);
|
||||
|
||||
esp_err_t alterEntryRangeState(size_t begin, size_t end, EntryState state);
|
||||
|
||||
esp_err_t alterPageState(PageState state);
|
||||
|
||||
esp_err_t readEntry(size_t index, Item& dst) const;
|
||||
|
||||
esp_err_t writeEntry(const Item& item);
|
||||
|
||||
esp_err_t writeEntryData(const uint8_t* data, size_t size);
|
||||
|
||||
esp_err_t eraseEntryAndSpan(size_t index);
|
||||
|
||||
void updateFirstUsedEntry(size_t index, size_t span);
|
||||
|
||||
static constexpr size_t getAlignmentForType(ItemType type)
|
||||
{
|
||||
return static_cast<uint8_t>(type) & 0x0f;
|
||||
}
|
||||
|
||||
uint32_t getEntryAddress(size_t entry) const
|
||||
{
|
||||
assert(entry < ENTRY_COUNT);
|
||||
return mBaseAddress + ENTRY_DATA_OFFSET + static_cast<uint32_t>(entry) * ENTRY_SIZE;
|
||||
}
|
||||
|
||||
static const char* pageStateToName(PageState ps);
|
||||
|
||||
|
||||
protected:
|
||||
uint32_t mBaseAddress = 0;
|
||||
PageState mState = PageState::INVALID;
|
||||
uint32_t mSeqNumber = UINT32_MAX;
|
||||
typedef CompressedEnumTable<EntryState, 2, ENTRY_COUNT> TEntryTable;
|
||||
TEntryTable mEntryTable;
|
||||
size_t mNextFreeEntry = INVALID_ENTRY;
|
||||
size_t mFirstUsedEntry = INVALID_ENTRY;
|
||||
uint16_t mUsedEntryCount = 0;
|
||||
uint16_t mErasedEntryCount = 0;
|
||||
|
||||
HashList mHashList;
|
||||
|
||||
static const uint32_t HEADER_OFFSET = 0;
|
||||
static const uint32_t ENTRY_TABLE_OFFSET = HEADER_OFFSET + 32;
|
||||
static const uint32_t ENTRY_DATA_OFFSET = ENTRY_TABLE_OFFSET + 32;
|
||||
|
||||
static_assert(sizeof(Header) == 32, "header size must be 32 bytes");
|
||||
static_assert(ENTRY_TABLE_OFFSET % 32 == 0, "entry table offset should be aligned");
|
||||
static_assert(ENTRY_DATA_OFFSET % 32 == 0, "entry data offset should be aligned");
|
||||
|
||||
}; // class Page
|
||||
|
||||
} // namespace nvs
|
||||
|
||||
|
||||
#endif /* nvs_page_hpp */
|
203
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_pagemanager.cpp
vendored
Normal file
203
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_pagemanager.cpp
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "nvs_pagemanager.hpp"
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount)
|
||||
{
|
||||
mBaseSector = baseSector;
|
||||
mPageCount = sectorCount;
|
||||
mPageList.clear();
|
||||
mFreePageList.clear();
|
||||
mPages.reset(new Page[sectorCount]);
|
||||
|
||||
for (uint32_t i = 0; i < sectorCount; ++i) {
|
||||
auto err = mPages[i].load(baseSector + i);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
uint32_t seqNumber;
|
||||
if (mPages[i].getSeqNumber(seqNumber) != ESP_OK) {
|
||||
mFreePageList.push_back(&mPages[i]);
|
||||
} else {
|
||||
auto pos = std::find_if(std::begin(mPageList), std::end(mPageList), [=](const Page& page) -> bool {
|
||||
uint32_t otherSeqNumber;
|
||||
return page.getSeqNumber(otherSeqNumber) == ESP_OK && otherSeqNumber > seqNumber;
|
||||
});
|
||||
if (pos == mPageList.end()) {
|
||||
mPageList.push_back(&mPages[i]);
|
||||
} else {
|
||||
mPageList.insert(pos, &mPages[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mPageList.empty()) {
|
||||
mSeqNumber = 0;
|
||||
return activatePage();
|
||||
} else {
|
||||
uint32_t lastSeqNo;
|
||||
ESP_ERROR_CHECK( mPageList.back().getSeqNumber(lastSeqNo) );
|
||||
mSeqNumber = lastSeqNo + 1;
|
||||
}
|
||||
|
||||
// if power went out after a new item for the given key was written,
|
||||
// but before the old one was erased, we end up with a duplicate item
|
||||
Page& lastPage = back();
|
||||
size_t lastItemIndex = SIZE_MAX;
|
||||
Item item;
|
||||
size_t itemIndex = 0;
|
||||
while (lastPage.findItem(Page::NS_ANY, ItemType::ANY, nullptr, itemIndex, item) == ESP_OK) {
|
||||
itemIndex += item.span;
|
||||
lastItemIndex = itemIndex;
|
||||
}
|
||||
|
||||
if (lastItemIndex != SIZE_MAX) {
|
||||
auto last = PageManager::TPageListIterator(&lastPage);
|
||||
for (auto it = begin(); it != last; ++it) {
|
||||
|
||||
if ((it->state() != Page::PageState::FREEING) &&
|
||||
(it->eraseItem(item.nsIndex, item.datatype, item.key) == ESP_OK)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if power went out while page was being freed
|
||||
for (auto it = begin(); it!= end(); ++it) {
|
||||
if (it->state() == Page::PageState::FREEING) {
|
||||
Page* newPage = &mPageList.back();
|
||||
if (newPage->state() == Page::PageState::ACTIVE) {
|
||||
auto err = newPage->erase();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
mPageList.erase(newPage);
|
||||
mFreePageList.push_back(newPage);
|
||||
}
|
||||
auto err = activatePage();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
newPage = &mPageList.back();
|
||||
|
||||
err = it->copyItems(*newPage);
|
||||
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = it->erase();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
Page* p = static_cast<Page*>(it);
|
||||
mPageList.erase(it);
|
||||
mFreePageList.push_back(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// partition should have at least one free page
|
||||
if (mFreePageList.size() == 0) {
|
||||
return ESP_ERR_NVS_NO_FREE_PAGES;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t PageManager::requestNewPage()
|
||||
{
|
||||
if (mFreePageList.empty()) {
|
||||
return ESP_ERR_NVS_INVALID_STATE;
|
||||
}
|
||||
|
||||
// do we have at least two free pages? in that case no erasing is required
|
||||
if (mFreePageList.size() >= 2) {
|
||||
return activatePage();
|
||||
}
|
||||
|
||||
// find the page with the higest number of erased items
|
||||
TPageListIterator maxUnusedItemsPageIt;
|
||||
size_t maxUnusedItems = 0;
|
||||
for (auto it = begin(); it != end(); ++it) {
|
||||
|
||||
auto unused = Page::ENTRY_COUNT - it->getUsedEntryCount();
|
||||
if (unused > maxUnusedItems) {
|
||||
maxUnusedItemsPageIt = it;
|
||||
maxUnusedItems = unused;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxUnusedItems == 0) {
|
||||
return ESP_ERR_NVS_NOT_ENOUGH_SPACE;
|
||||
}
|
||||
|
||||
esp_err_t err = activatePage();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
Page* newPage = &mPageList.back();
|
||||
|
||||
Page* erasedPage = maxUnusedItemsPageIt;
|
||||
|
||||
#ifndef NDEBUG
|
||||
size_t usedEntries = erasedPage->getUsedEntryCount();
|
||||
#endif
|
||||
err = erasedPage->markFreeing();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
err = erasedPage->copyItems(*newPage);
|
||||
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = erasedPage->erase();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
assert(usedEntries == newPage->getUsedEntryCount());
|
||||
#endif
|
||||
|
||||
mPageList.erase(maxUnusedItemsPageIt);
|
||||
mFreePageList.push_back(erasedPage);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t PageManager::activatePage()
|
||||
{
|
||||
if (mFreePageList.empty()) {
|
||||
return ESP_ERR_NVS_NOT_ENOUGH_SPACE;
|
||||
}
|
||||
Page* p = &mFreePageList.front();
|
||||
if (p->state() == Page::PageState::CORRUPT) {
|
||||
auto err = p->erase();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
mFreePageList.pop_front();
|
||||
mPageList.push_back(p);
|
||||
p->setSeqNumber(mSeqNumber);
|
||||
++mSeqNumber;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
} // namespace nvs
|
70
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_pagemanager.hpp
vendored
Normal file
70
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_pagemanager.hpp
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2015-2016 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 nvs_pagemanager_hpp
|
||||
#define nvs_pagemanager_hpp
|
||||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include "nvs_types.hpp"
|
||||
#include "nvs_page.hpp"
|
||||
#include "nvs_pagemanager.hpp"
|
||||
#include "intrusive_list.h"
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
class PageManager
|
||||
{
|
||||
using TPageList = intrusive_list<Page>;
|
||||
using TPageListIterator = TPageList::iterator;
|
||||
public:
|
||||
|
||||
PageManager() {}
|
||||
|
||||
esp_err_t load(uint32_t baseSector, uint32_t sectorCount);
|
||||
|
||||
TPageListIterator begin()
|
||||
{
|
||||
return mPageList.begin();
|
||||
}
|
||||
|
||||
TPageListIterator end()
|
||||
{
|
||||
return mPageList.end();
|
||||
}
|
||||
|
||||
Page& back()
|
||||
{
|
||||
return mPageList.back();
|
||||
}
|
||||
|
||||
esp_err_t requestNewPage();
|
||||
|
||||
protected:
|
||||
friend class Iterator;
|
||||
|
||||
esp_err_t activatePage();
|
||||
|
||||
TPageList mPageList;
|
||||
TPageList mFreePageList;
|
||||
std::unique_ptr<Page[]> mPages;
|
||||
uint32_t mBaseSector;
|
||||
uint32_t mPageCount;
|
||||
uint32_t mSeqNumber;
|
||||
}; // class PageManager
|
||||
|
||||
|
||||
} // namespace nvs
|
||||
|
||||
|
||||
#endif /* nvs_pagemanager_hpp */
|
81
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_platform.hpp
vendored
Normal file
81
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_platform.hpp
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright 2015-2016 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 nvs_platform_h
|
||||
#define nvs_platform_h
|
||||
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
class Lock
|
||||
{
|
||||
public:
|
||||
Lock()
|
||||
{
|
||||
if (mSemaphore) {
|
||||
xSemaphoreTake(mSemaphore, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
~Lock()
|
||||
{
|
||||
if (mSemaphore) {
|
||||
xSemaphoreGive(mSemaphore);
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t init()
|
||||
{
|
||||
if (mSemaphore) {
|
||||
return ESP_OK;
|
||||
}
|
||||
mSemaphore = xSemaphoreCreateMutex();
|
||||
if (!mSemaphore) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void uninit()
|
||||
{
|
||||
if (mSemaphore) {
|
||||
vSemaphoreDelete(mSemaphore);
|
||||
}
|
||||
mSemaphore = nullptr;
|
||||
}
|
||||
|
||||
static SemaphoreHandle_t mSemaphore;
|
||||
};
|
||||
} // namespace nvs
|
||||
|
||||
#else // ESP_PLATFORM
|
||||
namespace nvs
|
||||
{
|
||||
class Lock
|
||||
{
|
||||
public:
|
||||
Lock() { }
|
||||
~Lock() { }
|
||||
static void init() {}
|
||||
static void uninit() {}
|
||||
};
|
||||
} // namespace nvs
|
||||
#endif // ESP_PLATFORM
|
||||
|
||||
|
||||
#endif /* nvs_platform_h */
|
294
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_storage.cpp
vendored
Normal file
294
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_storage.cpp
vendored
Normal file
@ -0,0 +1,294 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "nvs_storage.hpp"
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
Storage::~Storage()
|
||||
{
|
||||
clearNamespaces();
|
||||
}
|
||||
|
||||
void Storage::clearNamespaces()
|
||||
{
|
||||
for (auto it = std::begin(mNamespaces); it != std::end(mNamespaces); ) {
|
||||
auto tmp = it;
|
||||
++it;
|
||||
mNamespaces.erase(tmp);
|
||||
delete static_cast<NamespaceEntry*>(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount)
|
||||
{
|
||||
auto err = mPageManager.load(baseSector, sectorCount);
|
||||
if (err != ESP_OK) {
|
||||
mState = StorageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
|
||||
// load namespaces list
|
||||
clearNamespaces();
|
||||
std::fill_n(mNamespaceUsage.data(), mNamespaceUsage.byteSize() / 4, 0);
|
||||
for (auto it = mPageManager.begin(); it != mPageManager.end(); ++it) {
|
||||
Page& p = *it;
|
||||
size_t itemIndex = 0;
|
||||
Item item;
|
||||
while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) {
|
||||
NamespaceEntry* entry = new NamespaceEntry;
|
||||
item.getKey(entry->mName, sizeof(entry->mName) - 1);
|
||||
item.getValue(entry->mIndex);
|
||||
mNamespaces.push_back(entry);
|
||||
mNamespaceUsage.set(entry->mIndex, true);
|
||||
itemIndex += item.span;
|
||||
}
|
||||
}
|
||||
mNamespaceUsage.set(0, true);
|
||||
mNamespaceUsage.set(255, true);
|
||||
mState = StorageState::ACTIVE;
|
||||
#ifndef ESP_PLATFORM
|
||||
debugCheck();
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool Storage::isValid() const
|
||||
{
|
||||
return mState == StorageState::ACTIVE;
|
||||
}
|
||||
|
||||
esp_err_t Storage::findItem(uint8_t nsIndex, ItemType datatype, const char* key, Page* &page, Item& item)
|
||||
{
|
||||
for (auto it = std::begin(mPageManager); it != std::end(mPageManager); ++it) {
|
||||
size_t itemIndex = 0;
|
||||
auto err = it->findItem(nsIndex, datatype, key, itemIndex, item);
|
||||
if (err == ESP_OK) {
|
||||
page = it;
|
||||
return ESP_OK;
|
||||
}
|
||||
}
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
|
||||
esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, const void* data, size_t dataSize)
|
||||
{
|
||||
if (mState != StorageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
Page* findPage = nullptr;
|
||||
Item item;
|
||||
auto err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) {
|
||||
return err;
|
||||
}
|
||||
|
||||
Page& page = getCurrentPage();
|
||||
err = page.writeItem(nsIndex, datatype, key, data, dataSize);
|
||||
if (err == ESP_ERR_NVS_PAGE_FULL) {
|
||||
if (page.state() != Page::PageState::FULL) {
|
||||
err = page.markFull();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = mPageManager.requestNewPage();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = getCurrentPage().writeItem(nsIndex, datatype, key, data, dataSize);
|
||||
if (err == ESP_ERR_NVS_PAGE_FULL) {
|
||||
return ESP_ERR_NVS_NOT_ENOUGH_SPACE;
|
||||
}
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
} else if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (findPage) {
|
||||
if (findPage->state() == Page::PageState::UNINITIALIZED ||
|
||||
findPage->state() == Page::PageState::INVALID) {
|
||||
ESP_ERROR_CHECK( findItem(nsIndex, datatype, key, findPage, item) );
|
||||
}
|
||||
err = findPage->eraseItem(nsIndex, datatype, key);
|
||||
if (err == ESP_ERR_FLASH_OP_FAIL) {
|
||||
return ESP_ERR_NVS_REMOVE_FAILED;
|
||||
}
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#ifndef ESP_PLATFORM
|
||||
debugCheck();
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Storage::createOrOpenNamespace(const char* nsName, bool canCreate, uint8_t& nsIndex)
|
||||
{
|
||||
if (mState != StorageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
auto it = std::find_if(mNamespaces.begin(), mNamespaces.end(), [=] (const NamespaceEntry& e) -> bool {
|
||||
return strncmp(nsName, e.mName, sizeof(e.mName) - 1) == 0;
|
||||
});
|
||||
if (it == std::end(mNamespaces)) {
|
||||
if (!canCreate) {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
|
||||
uint8_t ns;
|
||||
for (ns = 1; ns < 255; ++ns) {
|
||||
if (mNamespaceUsage.get(ns) == false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ns == 255) {
|
||||
return ESP_ERR_NVS_NOT_ENOUGH_SPACE;
|
||||
}
|
||||
|
||||
auto err = writeItem(Page::NS_INDEX, ItemType::U8, nsName, &ns, sizeof(ns));
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
mNamespaceUsage.set(ns, true);
|
||||
nsIndex = ns;
|
||||
|
||||
NamespaceEntry* entry = new NamespaceEntry;
|
||||
entry->mIndex = ns;
|
||||
strncpy(entry->mName, nsName, sizeof(entry->mName) - 1);
|
||||
entry->mName[sizeof(entry->mName) - 1] = 0;
|
||||
mNamespaces.push_back(entry);
|
||||
|
||||
} else {
|
||||
nsIndex = it->mIndex;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t Storage::readItem(uint8_t nsIndex, ItemType datatype, const char* key, void* data, size_t dataSize)
|
||||
{
|
||||
if (mState != StorageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
Item item;
|
||||
Page* findPage = nullptr;
|
||||
auto err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return findPage->readItem(nsIndex, datatype, key, data, dataSize);
|
||||
}
|
||||
|
||||
esp_err_t Storage::eraseItem(uint8_t nsIndex, ItemType datatype, const char* key)
|
||||
{
|
||||
if (mState != StorageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
Item item;
|
||||
Page* findPage = nullptr;
|
||||
auto err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return findPage->eraseItem(nsIndex, datatype, key);
|
||||
}
|
||||
|
||||
esp_err_t Storage::eraseNamespace(uint8_t nsIndex)
|
||||
{
|
||||
if (mState != StorageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
for (auto it = std::begin(mPageManager); it != std::end(mPageManager); ++it) {
|
||||
while (true) {
|
||||
auto err = it->eraseItem(nsIndex, ItemType::ANY, nullptr);
|
||||
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
||||
break;
|
||||
}
|
||||
else if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
|
||||
}
|
||||
|
||||
esp_err_t Storage::getItemDataSize(uint8_t nsIndex, ItemType datatype, const char* key, size_t& dataSize)
|
||||
{
|
||||
if (mState != StorageState::ACTIVE) {
|
||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
Item item;
|
||||
Page* findPage = nullptr;
|
||||
auto err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
dataSize = item.varLength.dataSize;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void Storage::debugDump()
|
||||
{
|
||||
for (auto p = mPageManager.begin(); p != mPageManager.end(); ++p) {
|
||||
p->debugDump();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
void Storage::debugCheck()
|
||||
{
|
||||
std::map<std::string, Page*> keys;
|
||||
|
||||
for (auto p = mPageManager.begin(); p != mPageManager.end(); ++p) {
|
||||
size_t itemIndex = 0;
|
||||
size_t usedCount = 0;
|
||||
Item item;
|
||||
while (p->findItem(Page::NS_ANY, ItemType::ANY, nullptr, itemIndex, item) == ESP_OK) {
|
||||
std::stringstream keyrepr;
|
||||
keyrepr << static_cast<unsigned>(item.nsIndex) << "_" << static_cast<unsigned>(item.datatype) << "_" << item.key;
|
||||
std::string keystr = keyrepr.str();
|
||||
if (keys.find(keystr) != std::end(keys)) {
|
||||
printf("Duplicate key: %s\n", keystr.c_str());
|
||||
debugDump();
|
||||
assert(0);
|
||||
}
|
||||
keys.insert(std::make_pair(keystr, static_cast<Page*>(p)));
|
||||
itemIndex += item.span;
|
||||
usedCount += item.span;
|
||||
}
|
||||
assert(usedCount == p->getUsedEntryCount());
|
||||
}
|
||||
}
|
||||
#endif //ESP_PLATFORM
|
||||
|
||||
}
|
117
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_storage.hpp
vendored
Normal file
117
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_storage.hpp
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
// Copyright 2015-2016 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 nvs_storage_hpp
|
||||
#define nvs_storage_hpp
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "nvs.hpp"
|
||||
#include "nvs_types.hpp"
|
||||
#include "nvs_page.hpp"
|
||||
#include "nvs_pagemanager.hpp"
|
||||
|
||||
//extern void dumpBytes(const uint8_t* data, size_t count);
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
class Storage : public intrusive_list_node<Storage>
|
||||
{
|
||||
enum class StorageState : uint32_t {
|
||||
INVALID,
|
||||
ACTIVE,
|
||||
};
|
||||
|
||||
struct NamespaceEntry : public intrusive_list_node<NamespaceEntry> {
|
||||
public:
|
||||
char mName[Item::MAX_KEY_LENGTH + 1];
|
||||
uint8_t mIndex;
|
||||
};
|
||||
|
||||
typedef intrusive_list<NamespaceEntry> TNamespaces;
|
||||
|
||||
public:
|
||||
~Storage();
|
||||
|
||||
Storage(const char *pName = NVS_DEFAULT_PART_NAME) : mPartitionName(pName) { };
|
||||
|
||||
esp_err_t init(uint32_t baseSector, uint32_t sectorCount);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
esp_err_t createOrOpenNamespace(const char* nsName, bool canCreate, uint8_t& nsIndex);
|
||||
|
||||
esp_err_t writeItem(uint8_t nsIndex, ItemType datatype, const char* key, const void* data, size_t dataSize);
|
||||
|
||||
esp_err_t readItem(uint8_t nsIndex, ItemType datatype, const char* key, void* data, size_t dataSize);
|
||||
|
||||
esp_err_t getItemDataSize(uint8_t nsIndex, ItemType datatype, const char* key, size_t& dataSize);
|
||||
|
||||
esp_err_t eraseItem(uint8_t nsIndex, ItemType datatype, const char* key);
|
||||
|
||||
template<typename T>
|
||||
esp_err_t writeItem(uint8_t nsIndex, const char* key, const T& value)
|
||||
{
|
||||
return writeItem(nsIndex, itemTypeOf(value), key, &value, sizeof(value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
esp_err_t readItem(uint8_t nsIndex, const char* key, T& value)
|
||||
{
|
||||
return readItem(nsIndex, itemTypeOf(value), key, &value, sizeof(value));
|
||||
}
|
||||
|
||||
esp_err_t eraseItem(uint8_t nsIndex, const char* key)
|
||||
{
|
||||
return eraseItem(nsIndex, ItemType::ANY, key);
|
||||
}
|
||||
|
||||
esp_err_t eraseNamespace(uint8_t nsIndex);
|
||||
|
||||
const char *getPartName() const
|
||||
{
|
||||
return mPartitionName;
|
||||
}
|
||||
|
||||
void debugDump();
|
||||
|
||||
void debugCheck();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Page& getCurrentPage()
|
||||
{
|
||||
return mPageManager.back();
|
||||
}
|
||||
|
||||
void clearNamespaces();
|
||||
|
||||
esp_err_t findItem(uint8_t nsIndex, ItemType datatype, const char* key, Page* &page, Item& item);
|
||||
|
||||
protected:
|
||||
const char *mPartitionName;
|
||||
size_t mPageCount;
|
||||
PageManager mPageManager;
|
||||
TNamespaces mNamespaces;
|
||||
CompressedEnumTable<bool, 1, 256> mNamespaceUsage;
|
||||
StorageState mState = StorageState::INVALID;
|
||||
};
|
||||
|
||||
} // namespace nvs
|
||||
|
||||
|
||||
|
||||
#endif /* nvs_storage_hpp */
|
50
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_test_api.h
vendored
Normal file
50
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_test_api.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nvs_flash.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize NVS flash storage with custom flash sector layout
|
||||
*
|
||||
* @note This API is intended to be used in unit tests.
|
||||
*
|
||||
* @param partName Partition name of the NVS partition as per partition table
|
||||
* @param baseSector Flash sector (units of 4096 bytes) offset to start NVS
|
||||
* @param sectorCount Length (in flash sectors) of NVS region.
|
||||
NVS partition must be at least 3 sectors long.
|
||||
* @return ESP_OK if flash was successfully initialized
|
||||
*/
|
||||
esp_err_t nvs_flash_init_custom(const char *partName, uint32_t baseSector, uint32_t sectorCount);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Dump contents of NVS storage to stdout
|
||||
*
|
||||
* This function may be used for debugging purposes to inspect the state
|
||||
* of NVS pages. For each page, list of entries is also dumped.
|
||||
*
|
||||
* @param partName Partition name of the NVS partition as per partition table
|
||||
*/
|
||||
void nvs_dump(const char *partName);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
56
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_types.cpp
vendored
Normal file
56
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_types.cpp
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "nvs_types.hpp"
|
||||
|
||||
#if defined(ESP_PLATFORM)
|
||||
#if defined(NVS_CRC_HEADER_FILE)
|
||||
#include NVS_CRC_HEADER_FILE
|
||||
#else
|
||||
#include <rom/crc.h>
|
||||
#endif
|
||||
#else
|
||||
#include "crc.h"
|
||||
#endif
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
uint32_t Item::calculateCrc32() const
|
||||
{
|
||||
uint32_t result = 0xffffffff;
|
||||
const uint8_t* p = reinterpret_cast<const uint8_t*>(this);
|
||||
result = crc32_le(result, p + offsetof(Item, nsIndex),
|
||||
offsetof(Item, crc32) - offsetof(Item, nsIndex));
|
||||
result = crc32_le(result, p + offsetof(Item, key), sizeof(key));
|
||||
result = crc32_le(result, p + offsetof(Item, data), sizeof(data));
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t Item::calculateCrc32WithoutValue() const
|
||||
{
|
||||
uint32_t result = 0xffffffff;
|
||||
const uint8_t* p = reinterpret_cast<const uint8_t*>(this);
|
||||
result = crc32_le(result, p + offsetof(Item, nsIndex),
|
||||
offsetof(Item, datatype) - offsetof(Item, nsIndex));
|
||||
result = crc32_le(result, p + offsetof(Item, key), sizeof(key));
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t Item::calculateCrc32(const uint8_t* data, size_t size)
|
||||
{
|
||||
uint32_t result = 0xffffffff;
|
||||
result = crc32_le(result, data, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace nvs
|
118
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_types.hpp
vendored
Normal file
118
cpu/esp8266/vendor/esp-idf/nvs_flash/src/nvs_types.hpp
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
// Copyright 2015-2016 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 nvs_types_h
|
||||
#define nvs_types_h
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include "nvs.h"
|
||||
#include "compressed_enum_table.hpp"
|
||||
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
enum class ItemType : uint8_t {
|
||||
U8 = 0x01,
|
||||
I8 = 0x11,
|
||||
U16 = 0x02,
|
||||
I16 = 0x12,
|
||||
U32 = 0x04,
|
||||
I32 = 0x14,
|
||||
U64 = 0x08,
|
||||
I64 = 0x18,
|
||||
SZ = 0x21,
|
||||
BLOB = 0x41,
|
||||
ANY = 0xff
|
||||
};
|
||||
|
||||
template<typename T, typename std::enable_if<std::is_integral<T>::value, void*>::type = nullptr>
|
||||
constexpr ItemType itemTypeOf()
|
||||
{
|
||||
return static_cast<ItemType>(((std::is_signed<T>::value)?0x10:0x00) | sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr ItemType itemTypeOf(const T&)
|
||||
{
|
||||
return itemTypeOf<T>();
|
||||
}
|
||||
|
||||
class Item
|
||||
{
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
uint8_t nsIndex;
|
||||
ItemType datatype;
|
||||
uint8_t span;
|
||||
uint8_t reserved;
|
||||
uint32_t crc32;
|
||||
char key[16];
|
||||
union {
|
||||
struct {
|
||||
uint16_t dataSize;
|
||||
uint16_t reserved2;
|
||||
uint32_t dataCrc32;
|
||||
} varLength;
|
||||
uint8_t data[8];
|
||||
};
|
||||
};
|
||||
uint8_t rawData[32];
|
||||
};
|
||||
|
||||
static const size_t MAX_KEY_LENGTH = sizeof(key) - 1;
|
||||
|
||||
Item(uint8_t nsIndex, ItemType datatype, uint8_t span, const char* key_)
|
||||
: nsIndex(nsIndex), datatype(datatype), span(span), reserved(0xff)
|
||||
{
|
||||
std::fill_n(reinterpret_cast<uint32_t*>(key), sizeof(key) / 4, 0xffffffff);
|
||||
std::fill_n(reinterpret_cast<uint32_t*>(data), sizeof(data) / 4, 0xffffffff);
|
||||
if (key_) {
|
||||
strncpy(key, key_, sizeof(key) - 1);
|
||||
key[sizeof(key) - 1] = 0;
|
||||
} else {
|
||||
key[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Item()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t calculateCrc32() const;
|
||||
uint32_t calculateCrc32WithoutValue() const;
|
||||
static uint32_t calculateCrc32(const uint8_t* data, size_t size);
|
||||
|
||||
void getKey(char* dst, size_t dstSize)
|
||||
{
|
||||
strncpy(dst, key, (dstSize<MAX_KEY_LENGTH)?dstSize:MAX_KEY_LENGTH);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void getValue(T& dst)
|
||||
{
|
||||
assert(itemTypeOf(dst) == datatype);
|
||||
dst = *reinterpret_cast<T*>(data);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nvs
|
||||
|
||||
|
||||
|
||||
#endif /* nvs_types_h */
|
389
cpu/esp8266/vendor/esp-idf/partition_table/gen_esp32part.py
vendored
Executable file
389
cpu/esp8266/vendor/esp-idf/partition_table/gen_esp32part.py
vendored
Executable file
@ -0,0 +1,389 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# ESP32 partition table generation tool
|
||||
#
|
||||
# Converts partition tables to/from CSV and binary formats.
|
||||
#
|
||||
# See http://esp-idf.readthedocs.io/en/latest/api-guides/partition-tables.html
|
||||
# for explanation of partition table structure and uses.
|
||||
#
|
||||
# Copyright 2015-2016 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.
|
||||
from __future__ import print_function, division
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
|
||||
MAX_PARTITION_LENGTH = 0xC00 # 3K for partition data (96 entries) leaves 1K in a 4K sector for signature
|
||||
|
||||
__version__ = '1.0'
|
||||
|
||||
quiet = False
|
||||
|
||||
def status(msg):
|
||||
""" Print status message to stderr """
|
||||
if not quiet:
|
||||
critical(msg)
|
||||
|
||||
def critical(msg):
|
||||
""" Print critical message to stderr """
|
||||
if not quiet:
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.write('\n')
|
||||
|
||||
class PartitionTable(list):
|
||||
def __init__(self):
|
||||
super(PartitionTable, self).__init__(self)
|
||||
|
||||
@classmethod
|
||||
def from_csv(cls, csv_contents):
|
||||
res = PartitionTable()
|
||||
lines = csv_contents.splitlines()
|
||||
|
||||
def expand_vars(f):
|
||||
f = os.path.expandvars(f)
|
||||
m = re.match(r'(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)', f)
|
||||
if m:
|
||||
raise InputError("unknown variable '%s'" % m.group(1))
|
||||
return f
|
||||
|
||||
for line_no in range(len(lines)):
|
||||
line = expand_vars(lines[line_no]).strip()
|
||||
if line.startswith("#") or len(line) == 0:
|
||||
continue
|
||||
try:
|
||||
res.append(PartitionDefinition.from_csv(line))
|
||||
except InputError as e:
|
||||
raise InputError("Error at line %d: %s" % (line_no+1, e))
|
||||
except Exception:
|
||||
critical("Unexpected error parsing line %d: %s" % (line_no+1, line))
|
||||
raise
|
||||
|
||||
# fix up missing offsets & negative sizes
|
||||
last_end = 0x5000 # first offset after partition table
|
||||
for e in res:
|
||||
if e.offset is None:
|
||||
pad_to = 0x10000 if e.type == PartitionDefinition.APP_TYPE else 4
|
||||
if last_end % pad_to != 0:
|
||||
last_end += pad_to - (last_end % pad_to)
|
||||
e.offset = last_end
|
||||
if e.size < 0:
|
||||
e.size = -e.size - e.offset
|
||||
last_end = e.offset + e.size
|
||||
|
||||
return res
|
||||
|
||||
def __getitem__(self, item):
|
||||
""" Allow partition table access via name as well as by
|
||||
numeric index. """
|
||||
if isinstance(item, str):
|
||||
for x in self:
|
||||
if x.name == item:
|
||||
return x
|
||||
raise ValueError("No partition entry named '%s'" % item)
|
||||
else:
|
||||
return super(PartitionTable, self).__getitem__(item)
|
||||
|
||||
def verify(self):
|
||||
# verify each partition individually
|
||||
for p in self:
|
||||
p.verify()
|
||||
# check for overlaps
|
||||
last = None
|
||||
for p in sorted(self, key=lambda x:x.offset):
|
||||
if p.offset < 0x5000:
|
||||
raise InputError("Partition offset 0x%x is below 0x5000" % p.offset)
|
||||
if last is not None and p.offset < last.offset + last.size:
|
||||
raise InputError("Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset+last.size-1))
|
||||
last = p
|
||||
|
||||
@classmethod
|
||||
def from_binary(cls, b):
|
||||
result = cls()
|
||||
for o in range(0,len(b),32):
|
||||
data = b[o:o+32]
|
||||
if len(data) != 32:
|
||||
raise InputError("Partition table length must be a multiple of 32 bytes")
|
||||
if data == b'\xFF'*32:
|
||||
return result # got end marker
|
||||
result.append(PartitionDefinition.from_binary(data))
|
||||
raise InputError("Partition table is missing an end-of-table marker")
|
||||
|
||||
def to_binary(self):
|
||||
result = b"".join(e.to_binary() for e in self)
|
||||
if len(result )>= MAX_PARTITION_LENGTH:
|
||||
raise InputError("Binary partition table length (%d) longer than max" % len(result))
|
||||
result += b"\xFF" * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing
|
||||
return result
|
||||
|
||||
def to_csv(self, simple_formatting=False):
|
||||
rows = [ "# Espressif ESP32 Partition Table",
|
||||
"# Name, Type, SubType, Offset, Size, Flags" ]
|
||||
rows += [ x.to_csv(simple_formatting) for x in self ]
|
||||
return "\n".join(rows) + "\n"
|
||||
|
||||
class PartitionDefinition(object):
|
||||
APP_TYPE = 0x00
|
||||
DATA_TYPE = 0x01
|
||||
TYPES = {
|
||||
"app" : APP_TYPE,
|
||||
"data" : DATA_TYPE,
|
||||
}
|
||||
|
||||
# Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h
|
||||
SUBTYPES = {
|
||||
APP_TYPE : {
|
||||
"factory" : 0x00,
|
||||
"test" : 0x20,
|
||||
},
|
||||
DATA_TYPE : {
|
||||
"ota" : 0x00,
|
||||
"phy" : 0x01,
|
||||
"nvs" : 0x02,
|
||||
"coredump" : 0x03,
|
||||
"esphttpd" : 0x80,
|
||||
"fat" : 0x81,
|
||||
"spiffs" : 0x82,
|
||||
},
|
||||
}
|
||||
|
||||
MAGIC_BYTES = b"\xAA\x50"
|
||||
|
||||
ALIGNMENT = {
|
||||
APP_TYPE : 0x1000,
|
||||
DATA_TYPE : 0x04,
|
||||
}
|
||||
|
||||
# dictionary maps flag name (as used in CSV flags list, property name)
|
||||
# to bit set in flags words in binary format
|
||||
FLAGS = {
|
||||
"encrypted" : 0
|
||||
}
|
||||
|
||||
# add subtypes for the 16 OTA slot values ("ota_XXX, etc.")
|
||||
for ota_slot in range(16):
|
||||
SUBTYPES[TYPES["app"]]["ota_%d" % ota_slot] = 0x10 + ota_slot
|
||||
|
||||
def __init__(self):
|
||||
self.name = ""
|
||||
self.type = None
|
||||
self.subtype = None
|
||||
self.offset = None
|
||||
self.size = None
|
||||
self.encrypted = False
|
||||
|
||||
@classmethod
|
||||
def from_csv(cls, line):
|
||||
""" Parse a line from the CSV """
|
||||
line_w_defaults = line + ",,,," # lazy way to support default fields
|
||||
fields = [ f.strip() for f in line_w_defaults.split(",") ]
|
||||
|
||||
res = PartitionDefinition()
|
||||
res.name = fields[0]
|
||||
res.type = res.parse_type(fields[1])
|
||||
res.subtype = res.parse_subtype(fields[2])
|
||||
res.offset = res.parse_address(fields[3])
|
||||
res.size = res.parse_address(fields[4])
|
||||
if res.size is None:
|
||||
raise InputError("Size field can't be empty")
|
||||
|
||||
flags = fields[5].split(":")
|
||||
for flag in flags:
|
||||
if flag in cls.FLAGS:
|
||||
setattr(res, flag, True)
|
||||
elif len(flag) > 0:
|
||||
raise InputError("CSV flag column contains unknown flag '%s'" % (flag))
|
||||
|
||||
return res
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.name == other.name and self.type == other.type \
|
||||
and self.subtype == other.subtype and self.offset == other.offset \
|
||||
and self.size == other.size
|
||||
|
||||
def __repr__(self):
|
||||
def maybe_hex(x):
|
||||
return "0x%x" % x if x is not None else "None"
|
||||
return "PartitionDefinition('%s', 0x%x, 0x%x, %s, %s)" % (self.name, self.type, self.subtype or 0,
|
||||
maybe_hex(self.offset), maybe_hex(self.size))
|
||||
|
||||
def __str__(self):
|
||||
return "Part '%s' %d/%d @ 0x%x size 0x%x" % (self.name, self.type, self.subtype, self.offset or -1, self.size or -1)
|
||||
|
||||
def __cmp__(self, other):
|
||||
return self.offset - other.offset
|
||||
|
||||
def parse_type(self, strval):
|
||||
if strval == "":
|
||||
raise InputError("Field 'type' can't be left empty.")
|
||||
return parse_int(strval, self.TYPES)
|
||||
|
||||
def parse_subtype(self, strval):
|
||||
if strval == "":
|
||||
return 0 # default
|
||||
return parse_int(strval, self.SUBTYPES.get(self.type, {}))
|
||||
|
||||
def parse_address(self, strval):
|
||||
if strval == "":
|
||||
return None # PartitionTable will fill in default
|
||||
return parse_int(strval)
|
||||
|
||||
def verify(self):
|
||||
if self.type is None:
|
||||
raise ValidationError(self, "Type field is not set")
|
||||
if self.subtype is None:
|
||||
raise ValidationError(self, "Subtype field is not set")
|
||||
if self.offset is None:
|
||||
raise ValidationError(self, "Offset field is not set")
|
||||
align = self.ALIGNMENT.get(self.type, 4)
|
||||
if self.offset % align:
|
||||
raise ValidationError(self, "Offset 0x%x is not aligned to 0x%x" % (self.offset, align))
|
||||
if self.size is None:
|
||||
raise ValidationError(self, "Size field is not set")
|
||||
|
||||
STRUCT_FORMAT = "<2sBBLL16sL"
|
||||
|
||||
@classmethod
|
||||
def from_binary(cls, b):
|
||||
if len(b) != 32:
|
||||
raise InputError("Partition definition length must be exactly 32 bytes. Got %d bytes." % len(b))
|
||||
res = cls()
|
||||
(magic, res.type, res.subtype, res.offset,
|
||||
res.size, res.name, flags) = struct.unpack(cls.STRUCT_FORMAT, b)
|
||||
if b"\x00" in res.name: # strip null byte padding from name string
|
||||
res.name = res.name[:res.name.index(b"\x00")]
|
||||
res.name = res.name.decode()
|
||||
if magic != cls.MAGIC_BYTES:
|
||||
raise InputError("Invalid magic bytes (%r) for partition definition" % magic)
|
||||
for flag,bit in cls.FLAGS.items():
|
||||
if flags & (1<<bit):
|
||||
setattr(res, flag, True)
|
||||
flags &= ~(1<<bit)
|
||||
if flags != 0:
|
||||
critical("WARNING: Partition definition had unknown flag(s) 0x%08x. Newer binary format?" % flags)
|
||||
return res
|
||||
|
||||
def get_flags_list(self):
|
||||
return [ flag for flag in self.FLAGS.keys() if getattr(self, flag) ]
|
||||
|
||||
def to_binary(self):
|
||||
flags = sum((1 << self.FLAGS[flag]) for flag in self.get_flags_list())
|
||||
return struct.pack(self.STRUCT_FORMAT,
|
||||
self.MAGIC_BYTES,
|
||||
self.type, self.subtype,
|
||||
self.offset, self.size,
|
||||
self.name.encode(),
|
||||
flags)
|
||||
|
||||
def to_csv(self, simple_formatting=False):
|
||||
def addr_format(a, include_sizes):
|
||||
if not simple_formatting and include_sizes:
|
||||
for (val, suffix) in [ (0x100000, "M"), (0x400, "K") ]:
|
||||
if a % val == 0:
|
||||
return "%d%s" % (a // val, suffix)
|
||||
return "0x%x" % a
|
||||
|
||||
def lookup_keyword(t, keywords):
|
||||
for k,v in keywords.items():
|
||||
if simple_formatting == False and t == v:
|
||||
return k
|
||||
return "%d" % t
|
||||
|
||||
def generate_text_flags():
|
||||
""" colon-delimited list of flags """
|
||||
return ":".join(self.get_flags_list())
|
||||
|
||||
return ",".join([ self.name,
|
||||
lookup_keyword(self.type, self.TYPES),
|
||||
lookup_keyword(self.subtype, self.SUBTYPES.get(self.type, {})),
|
||||
addr_format(self.offset, False),
|
||||
addr_format(self.size, True),
|
||||
generate_text_flags()])
|
||||
|
||||
|
||||
def parse_int(v, keywords={}):
|
||||
"""Generic parser for integer fields - int(x,0) with provision for
|
||||
k/m/K/M suffixes and 'keyword' value lookup.
|
||||
"""
|
||||
try:
|
||||
for letter, multiplier in [ ("k",1024), ("m",1024*1024) ]:
|
||||
if v.lower().endswith(letter):
|
||||
return parse_int(v[:-1], keywords) * multiplier
|
||||
return int(v, 0)
|
||||
except ValueError:
|
||||
if len(keywords) == 0:
|
||||
raise InputError("Invalid field value %s" % v)
|
||||
try:
|
||||
return keywords[v.lower()]
|
||||
except KeyError:
|
||||
raise InputError("Value '%s' is not valid. Known keywords: %s" % (v, ", ".join(keywords)))
|
||||
|
||||
def main():
|
||||
global quiet
|
||||
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
||||
|
||||
parser.add_argument('--verify', '-v', help='Verify partition table fields', default=True, action='store_false')
|
||||
parser.add_argument('--quiet', '-q', help="Don't print status messages to stderr", action='store_true')
|
||||
|
||||
parser.add_argument('input', help='Path to CSV or binary file to parse. Will use stdin if omitted.', type=argparse.FileType('rb'), default=sys.stdin)
|
||||
parser.add_argument('output', help='Path to output converted binary or CSV file. Will use stdout if omitted, unless the --display argument is also passed (in which case only the summary is printed.)',
|
||||
nargs='?',
|
||||
default='-')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
quiet = args.quiet
|
||||
input = args.input.read()
|
||||
input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
|
||||
if input_is_binary:
|
||||
status("Parsing binary partition input...")
|
||||
table = PartitionTable.from_binary(input)
|
||||
else:
|
||||
input = input.decode()
|
||||
status("Parsing CSV input...")
|
||||
table = PartitionTable.from_csv(input)
|
||||
|
||||
if args.verify:
|
||||
status("Verifying table...")
|
||||
table.verify()
|
||||
|
||||
if input_is_binary:
|
||||
output = table.to_csv()
|
||||
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
|
||||
f.write(output)
|
||||
else:
|
||||
output = table.to_binary()
|
||||
with sys.stdout.buffer if args.output == '-' else open(args.output, 'wb') as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
class InputError(RuntimeError):
|
||||
def __init__(self, e):
|
||||
super(InputError, self).__init__(e)
|
||||
|
||||
|
||||
class ValidationError(InputError):
|
||||
def __init__(self, partition, message):
|
||||
super(ValidationError, self).__init__(
|
||||
"Partition %s invalid: %s" % (partition.name, message))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except InputError as e:
|
||||
print(e, file=sys.stderr)
|
||||
sys.exit(2)
|
22
cpu/esp8266/vendor/esp-idf/sdkconfig.h
vendored
Normal file
22
cpu/esp8266/vendor/esp-idf/sdkconfig.h
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Gunar Schorcht
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_esp8266
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief SDK configuration wrapper file
|
||||
*
|
||||
* This file include the SDK configuration parameter file for source
|
||||
* code compatibility with the SDK.
|
||||
*
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*/
|
||||
|
||||
#include "sdk_conf.h"
|
5
cpu/esp8266/vendor/esp-idf/spi_flash/Makefile
vendored
Normal file
5
cpu/esp8266/vendor/esp-idf/spi_flash/Makefile
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
MODULE=esp_idf_spi_flash
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/bootloader_support/include
|
779
cpu/esp8266/vendor/esp-idf/spi_flash/spi_flash.c
vendored
Normal file
779
cpu/esp8266/vendor/esp-idf/spi_flash/spi_flash.c
vendored
Normal file
@ -0,0 +1,779 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "spi_flash.h"
|
||||
#include "esp8266/spi_register.h"
|
||||
#include "esp8266/pin_mux_register.h"
|
||||
#include "priv/esp_spi_flash_raw.h"
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "esp_wifi_osi.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "esp_image_format.h"
|
||||
|
||||
#define SPI_FLASH_ISSI_ENABLE_QIO_MODE (BIT(6))
|
||||
|
||||
/*gd25q32c*/
|
||||
#define SPI_FLASH_GD25Q32C_WRITE_STATUSE1_CMD (0X01)
|
||||
#define SPI_FLASH_GD25Q32C_WRITE_STATUSE2_CMD (0X31)
|
||||
#define SPI_FLASH_GD25Q32C_WRITE_STATUSE3_CMD (0X11)
|
||||
|
||||
#define SPI_FLASH_GD25Q32C_READ_STATUSE1_CMD (0X05)
|
||||
#define SPI_FLASH_GD25Q32C_READ_STATUSE2_CMD (0X35)
|
||||
#define SPI_FLASH_GD25Q32C_READ_STATUSE3_CMD (0X15)
|
||||
|
||||
#define SPI_FLASH_GD25Q32C_QIO_MODE (BIT(1))
|
||||
|
||||
#define SPI_ISSI_FLASH_WRITE_PROTECT_STATUS (BIT(2)|BIT(3)|BIT(4)|BIT(5))
|
||||
#define SPI_EON_25Q16A_WRITE_PROTECT_STATUS (BIT(2)|BIT(3)|BIT(4)|BIT(5))
|
||||
#define SPI_EON_25Q16B_WRITE_PROTECT_STATUS (BIT(2)|BIT(3)|BIT(4)|BIT(5))
|
||||
#define SPI_GD25Q32_FLASH_WRITE_PROTECT_STATUS (BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6))
|
||||
#define SPI_FLASH_RDSR2 0x35
|
||||
#define SPI_FLASH_PROTECT_STATUS (BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(14))
|
||||
|
||||
#ifndef BOOTLOADER_BUILD
|
||||
#define FLASH_INTR_DECLARE(t)
|
||||
#define FLASH_INTR_LOCK(t) vPortEnterCritical()
|
||||
#define FLASH_INTR_UNLOCK(t) vPortExitCritical()
|
||||
#else
|
||||
#define FLASH_INTR_DECLARE(t)
|
||||
#define FLASH_INTR_LOCK(t)
|
||||
#define FLASH_INTR_UNLOCK(t)
|
||||
#endif
|
||||
|
||||
#define FLASH_ALIGN_BYTES 4
|
||||
#define FLASH_ALIGN(addr) ((((size_t)addr) + (FLASH_ALIGN_BYTES - 1)) & (~(FLASH_ALIGN_BYTES - 1)))
|
||||
#define FLASH_ALIGN_BEFORE(addr) (FLASH_ALIGN(addr) - 4)
|
||||
#define NOT_ALIGN(addr) (((size_t)addr) & (FLASH_ALIGN_BYTES - 1))
|
||||
#define IS_ALIGN(addr) (NOT_ALIGN(addr) == 0)
|
||||
|
||||
extern void vPortEnterCritical(void);
|
||||
extern void vPortExitCritical(void);
|
||||
|
||||
esp_spi_flash_chip_t flashchip = {
|
||||
0x1640ef,
|
||||
CONFIG_SPI_FLASH_SIZE,
|
||||
64 * 1024,
|
||||
4 * 1024,
|
||||
256,
|
||||
0xffff
|
||||
};
|
||||
|
||||
uint8_t FlashIsOnGoing = 0;
|
||||
|
||||
bool spi_user_cmd(spi_cmd_dir_t mode, spi_cmd_t *p_cmd)
|
||||
{
|
||||
bool ret;
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
if ((p_cmd->addr_len != 0 && p_cmd->addr == NULL)
|
||||
|| (p_cmd->data_len != 0 && p_cmd->data == NULL)
|
||||
|| (p_cmd == NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
ret = spi_user_cmd_raw(&flashchip, mode, p_cmd);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool special_flash_read_status(uint8_t command, uint32_t* status, int len)
|
||||
{
|
||||
bool ret;
|
||||
spi_cmd_t cmd;
|
||||
|
||||
if( len > 2 || len < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cmd.cmd = command;
|
||||
cmd.cmd_len = 1;
|
||||
cmd.addr = NULL;
|
||||
cmd.addr_len = 0;
|
||||
cmd.dummy_bits = 0;
|
||||
cmd.data = status;
|
||||
cmd.data_len = len;
|
||||
|
||||
ret = spi_user_cmd(SPI_RX, &cmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool special_flash_write_status(uint8_t command, uint32_t status, int len, bool write_en)
|
||||
{
|
||||
bool ret;
|
||||
spi_cmd_t cmd;
|
||||
|
||||
if (len > 2 || len < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cmd.cmd = command;
|
||||
cmd.cmd_len = 1;
|
||||
cmd.addr = NULL;
|
||||
cmd.addr_len = 0;
|
||||
cmd.dummy_bits = 0;
|
||||
cmd.data = &status;
|
||||
cmd.data_len = len > 1 ? 2 : 1;
|
||||
if (write_en) {
|
||||
ret = spi_user_cmd(SPI_WRSR, &cmd);
|
||||
} else {
|
||||
ret = spi_user_cmd(SPI_TX | SPI_RAW, &cmd);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t en25q16x_read_sfdp(void)
|
||||
{
|
||||
spi_cmd_t cmd;
|
||||
uint32_t addr = 0x00003000;
|
||||
uint32_t data = 0;
|
||||
|
||||
cmd.cmd = 0x5a;
|
||||
cmd.cmd_len = 1;
|
||||
|
||||
cmd.addr = &addr;
|
||||
cmd.addr_len = 3;
|
||||
cmd.dummy_bits = 8;
|
||||
|
||||
cmd.data = &data;
|
||||
cmd.data_len = 1;
|
||||
|
||||
spi_user_cmd(SPI_RX, &cmd);
|
||||
|
||||
return ((uint8_t) data);
|
||||
}
|
||||
|
||||
uint32_t spi_flash_get_id(void)
|
||||
{
|
||||
uint32_t rdid = 0;
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
rdid = spi_flash_get_id_raw(&flashchip);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return rdid;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_read_status(uint32_t *status)
|
||||
{
|
||||
esp_err_t ret;
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
ret = spi_flash_read_status_raw(&flashchip, status);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_write_status(uint32_t status_value)
|
||||
{
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
spi_flash_write_status_raw(&flashchip, status_value);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool spi_flash_check_wr_protect(void)
|
||||
{
|
||||
uint32_t flash_id=spi_flash_get_id();
|
||||
uint32_t status=0;
|
||||
//check for EN25Q16A/B flash chips
|
||||
if ((flash_id & 0xffffff) == 0x15701c) {
|
||||
uint8_t sfdp = en25q16x_read_sfdp();
|
||||
if (sfdp == 0xE5) {
|
||||
//This is EN25Q16A, set bit6 in the same way as issi flash chips.
|
||||
if(spi_flash_read_status(&status)==0) { //Read status Ok
|
||||
if(status&(SPI_EON_25Q16A_WRITE_PROTECT_STATUS)) { //Write_protect
|
||||
special_flash_write_status(0x1, status&(~(SPI_EON_25Q16A_WRITE_PROTECT_STATUS)), 1, true);
|
||||
}
|
||||
}
|
||||
} else if (sfdp == 0xED) {
|
||||
//This is EN25Q16B
|
||||
if(spi_flash_read_status(&status)==0) { //Read status Ok
|
||||
if(status&(SPI_EON_25Q16B_WRITE_PROTECT_STATUS)) { //Write_protect
|
||||
special_flash_write_status(0x1, status&(~(SPI_EON_25Q16B_WRITE_PROTECT_STATUS)), 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//MXIC :0XC2
|
||||
//ISSI :0X9D
|
||||
// ets_printf("spi_flash_check_wr_protect\r\n");
|
||||
else if(((flash_id&0xFF)==0X9D)||((flash_id&0xFF)==0XC2)||((flash_id & 0xFF) == 0x1C)) {
|
||||
if(spi_flash_read_status(&status)==0) { //Read status Ok
|
||||
if(status&(SPI_ISSI_FLASH_WRITE_PROTECT_STATUS)) { //Write_protect
|
||||
special_flash_write_status(0x1, status&(~(SPI_ISSI_FLASH_WRITE_PROTECT_STATUS)), 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//GD25Q32C:0X16409D
|
||||
//GD25Q128
|
||||
else if(((flash_id&0xFFFFFFFF)==0X1640C8)||((flash_id&0xFFFFFFFF)==0X1840C8)) {
|
||||
if(spi_flash_read_status(&status)==0) { //Read status Ok
|
||||
if(status&SPI_GD25Q32_FLASH_WRITE_PROTECT_STATUS) {
|
||||
special_flash_write_status(0x01, status&(~(SPI_GD25Q32_FLASH_WRITE_PROTECT_STATUS)), 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Others
|
||||
else {
|
||||
if(spi_flash_read_status(&status)==0) { //Read status Ok
|
||||
uint32_t status1 = 0; //flash_gd25q32c_read_status(GD25Q32C_STATUS2);
|
||||
special_flash_read_status(SPI_FLASH_RDSR2, &status1, 1);
|
||||
status=(status1 << 8)|(status & 0xff);
|
||||
if(status&SPI_FLASH_PROTECT_STATUS) {
|
||||
status=((status&(~SPI_FLASH_PROTECT_STATUS))&0xffff);
|
||||
spi_flash_write_status(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void spi_flash_enable_qio_bit6(void)
|
||||
{
|
||||
uint8_t wrsr_cmd = 0x1;
|
||||
uint32_t issi_qio = SPI_FLASH_ISSI_ENABLE_QIO_MODE;
|
||||
special_flash_write_status(wrsr_cmd, issi_qio, 1, true);
|
||||
}
|
||||
|
||||
static bool spi_flash_issi_enable_QIO_mode(void)
|
||||
{
|
||||
uint32_t status = 0;
|
||||
if(spi_flash_read_status(&status) == 0) {
|
||||
if((status&SPI_FLASH_ISSI_ENABLE_QIO_MODE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
spi_flash_enable_qio_bit6();
|
||||
|
||||
if(spi_flash_read_status(&status) == 0) {
|
||||
if((status&SPI_FLASH_ISSI_ENABLE_QIO_MODE)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t flash_gd25q32c_read_status(enum GD25Q32C_status status_index)
|
||||
{
|
||||
uint8_t rdsr_cmd=0;
|
||||
if(GD25Q32C_STATUS1 == status_index) {
|
||||
rdsr_cmd = SPI_FLASH_GD25Q32C_READ_STATUSE1_CMD;
|
||||
}
|
||||
else if(GD25Q32C_STATUS2 == status_index) {
|
||||
rdsr_cmd = SPI_FLASH_GD25Q32C_READ_STATUSE2_CMD;
|
||||
}
|
||||
else if(GD25Q32C_STATUS3 == status_index) {
|
||||
rdsr_cmd = SPI_FLASH_GD25Q32C_READ_STATUSE3_CMD;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
uint32_t status;
|
||||
special_flash_read_status(rdsr_cmd, &status, 1);
|
||||
return ((uint8_t)status);
|
||||
}
|
||||
|
||||
static void flash_gd25q32c_write_status(enum GD25Q32C_status status_index,uint8_t status)
|
||||
{
|
||||
uint32_t wrsr_cmd=0;
|
||||
uint32_t new_status = status;
|
||||
if(GD25Q32C_STATUS1 == status_index) {
|
||||
wrsr_cmd = SPI_FLASH_GD25Q32C_WRITE_STATUSE1_CMD;
|
||||
}
|
||||
else if(GD25Q32C_STATUS2 == status_index) {
|
||||
wrsr_cmd = SPI_FLASH_GD25Q32C_WRITE_STATUSE2_CMD;
|
||||
}
|
||||
else if(GD25Q32C_STATUS3 == status_index) {
|
||||
wrsr_cmd = SPI_FLASH_GD25Q32C_WRITE_STATUSE3_CMD;
|
||||
}
|
||||
else {
|
||||
//ets_printf("[ERR]Not konw GD25Q32C status idx %d\n ",spi_wr_status_cmd);
|
||||
}
|
||||
special_flash_write_status(wrsr_cmd, new_status, 1, true);
|
||||
}
|
||||
|
||||
static bool flash_gd25q32c_enable_QIO_mode(void)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
if((data=flash_gd25q32c_read_status(GD25Q32C_STATUS2))&SPI_FLASH_GD25Q32C_QIO_MODE) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
flash_gd25q32c_write_status(GD25Q32C_STATUS2,SPI_FLASH_GD25Q32C_QIO_MODE);
|
||||
if(flash_gd25q32c_read_status(GD25Q32C_STATUS2)&SPI_FLASH_GD25Q32C_QIO_MODE) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void special_flash_set_mode(uint8_t command, bool disable_wait_idle)
|
||||
{
|
||||
spi_cmd_t cmd;
|
||||
cmd.cmd = command;
|
||||
cmd.cmd_len = 1;
|
||||
cmd.addr = NULL;
|
||||
cmd.addr_len = 0;
|
||||
cmd.dummy_bits = 0;
|
||||
cmd.data = NULL;
|
||||
cmd.data_len = 0;
|
||||
if (disable_wait_idle) {
|
||||
spi_user_cmd(SPI_TX | SPI_RAW, &cmd);
|
||||
} else {
|
||||
spi_user_cmd(SPI_TX, &cmd);
|
||||
}
|
||||
}
|
||||
|
||||
bool en25q16x_write_volatile_status(uint8_t vsr)
|
||||
{
|
||||
//enter OTP mode
|
||||
special_flash_set_mode(0x3a, true);
|
||||
//volatile status register write enable
|
||||
special_flash_set_mode(0x50, true);
|
||||
//send 0x01 + 0x40 to set WHDIS bit
|
||||
special_flash_write_status(0x01, vsr, 1, false);
|
||||
//check
|
||||
uint32_t status = 0;
|
||||
special_flash_read_status(0x05, &status, 1);
|
||||
//Leave OTP mode
|
||||
special_flash_set_mode(0x04, false);
|
||||
|
||||
if (status == 0x40) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void user_spi_flash_dio_to_qio_pre_init(void)
|
||||
{
|
||||
uint32_t flash_id = spi_flash_get_id();
|
||||
bool to_qio = false;
|
||||
//check for EN25Q16A/B flash chips
|
||||
if ((flash_id & 0xffffff) == 0x15701c) {
|
||||
uint8_t sfdp = en25q16x_read_sfdp();
|
||||
if (sfdp == 0xE5) {
|
||||
//This is EN25Q16A, set bit6 in the same way as issi flash chips.
|
||||
if (spi_flash_issi_enable_QIO_mode() == true) {
|
||||
to_qio = true;
|
||||
}
|
||||
} else if (sfdp == 0xED) {
|
||||
//This is EN25Q16B
|
||||
if (en25q16x_write_volatile_status(0x40) == true) {
|
||||
to_qio = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ISSI : 0x9D
|
||||
// MXIC : 0xC2
|
||||
// GD25Q32C & GD25Q128C : 0x1640C8
|
||||
// EON : 0X1C
|
||||
// ENABLE FLASH QIO 0X01H+BIT6
|
||||
else if (((flash_id & 0xFF) == 0x9D) || ((flash_id & 0xFF) == 0xC2) || ((flash_id & 0xFF) == 0x1C) ) {
|
||||
if (spi_flash_issi_enable_QIO_mode() == true) {
|
||||
to_qio = true;
|
||||
}
|
||||
//ENABLE FLASH QIO 0X31H+BIT2
|
||||
} else if (((flash_id & 0xFFFFFF) == 0x1640C8) || ((flash_id & 0xFFFFFF) == 0x1840C8)) {
|
||||
if (flash_gd25q32c_enable_QIO_mode() == true) {
|
||||
to_qio = true;
|
||||
}
|
||||
//ENBALE FLASH QIO 0X01H+0X00+0X02
|
||||
} else {
|
||||
if (spi_flash_enable_qmode_raw(&flashchip) == ESP_OK) {
|
||||
to_qio = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (to_qio == true) {
|
||||
spi_flash_switch_to_qio_raw();
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_erase_sector(size_t sec)
|
||||
{
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
esp_err_t ret;
|
||||
|
||||
if (sec >= (flashchip.chip_size / flashchip.sector_size)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if (spi_flash_check_wr_protect() == false) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
ret = spi_flash_erase_sector_raw(&flashchip, sec, flashchip.sector_size);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t spi_flash_program(uint32_t target, uint32_t *src_addr, size_t len)
|
||||
{
|
||||
uint32_t page_size;
|
||||
uint32_t pgm_len, pgm_num;
|
||||
uint8_t i;
|
||||
|
||||
page_size = flashchip.page_size;
|
||||
pgm_len = page_size - (target % page_size);
|
||||
|
||||
if (len < pgm_len) {
|
||||
if (ESP_OK != spi_flash_write_raw(&flashchip, target, src_addr, len)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
} else {
|
||||
if (ESP_OK != spi_flash_write_raw(&flashchip, target, src_addr, pgm_len)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
//whole page program
|
||||
pgm_num = (len - pgm_len) / page_size;
|
||||
|
||||
for (i = 0; i < pgm_num; i++) {
|
||||
if (ESP_OK != spi_flash_write_raw(&flashchip, target + pgm_len, src_addr + (pgm_len >> 2), page_size)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
pgm_len += page_size;
|
||||
}
|
||||
|
||||
//remain parts to program
|
||||
if (ESP_OK != spi_flash_write_raw(&flashchip, target + pgm_len, src_addr + (pgm_len >> 2), len - pgm_len)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t __spi_flash_write(size_t dest_addr, const void *src, size_t size)
|
||||
{
|
||||
esp_err_t ret;
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
ret = spi_flash_program(dest_addr, (uint32_t *)src, size);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_write(size_t dest_addr, const void *src, size_t size)
|
||||
{
|
||||
#undef FLASH_WRITE
|
||||
#define FLASH_WRITE(dest, src, size) \
|
||||
{ \
|
||||
ret = __spi_flash_write(dest, src, size); \
|
||||
esp_task_wdt_reset(); \
|
||||
if (ret) { \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
|
||||
#undef FLASH_READ
|
||||
#define FLASH_READ(dest, src, size) \
|
||||
{ \
|
||||
ret = spi_flash_read(dest, src, size); \
|
||||
if (ret) { \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
|
||||
esp_err_t ret = ESP_ERR_FLASH_OP_FAIL;
|
||||
uint8_t *tmp = (uint8_t *)src;
|
||||
|
||||
if (!size)
|
||||
return ESP_OK;
|
||||
|
||||
if (src == NULL) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if ((dest_addr + size) > flashchip.chip_size) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if (spi_flash_check_wr_protect() == false) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if (NOT_ALIGN(dest_addr)
|
||||
|| NOT_ALIGN(tmp)
|
||||
|| NOT_ALIGN(size)
|
||||
|| IS_FLASH(src)) {
|
||||
uint8_t buf[SPI_READ_BUF_MAX];
|
||||
|
||||
if (NOT_ALIGN(dest_addr)) {
|
||||
size_t r_addr = FLASH_ALIGN_BEFORE(dest_addr);
|
||||
size_t c_off = dest_addr - r_addr;
|
||||
size_t wbytes = FLASH_ALIGN_BYTES - c_off;
|
||||
|
||||
wbytes = wbytes > size ? size : wbytes;
|
||||
|
||||
FLASH_READ(r_addr, buf, FLASH_ALIGN_BYTES);
|
||||
memcpy(&buf[c_off], tmp, wbytes);
|
||||
FLASH_WRITE(r_addr, buf, FLASH_ALIGN_BYTES);
|
||||
|
||||
dest_addr += wbytes;
|
||||
tmp += wbytes;
|
||||
size -= wbytes;
|
||||
}
|
||||
|
||||
while (size > 0) {
|
||||
size_t len = size >= SPI_READ_BUF_MAX ? SPI_READ_BUF_MAX : size;
|
||||
size_t wlen = FLASH_ALIGN(len);
|
||||
|
||||
if (wlen != len) {
|
||||
size_t l_b = wlen - FLASH_ALIGN_BYTES;
|
||||
|
||||
FLASH_READ(dest_addr + l_b, &buf[l_b], FLASH_ALIGN_BYTES);
|
||||
}
|
||||
|
||||
memcpy(buf, tmp, len);
|
||||
|
||||
FLASH_WRITE(dest_addr, buf, wlen);
|
||||
|
||||
dest_addr += len;
|
||||
tmp += len;
|
||||
size -= len;
|
||||
}
|
||||
} else {
|
||||
FLASH_WRITE(dest_addr, src, size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t __spi_flash_read(size_t src_addr, void *dest, size_t size)
|
||||
{
|
||||
esp_err_t ret;
|
||||
FLASH_INTR_DECLARE(c_tmp);
|
||||
|
||||
FLASH_INTR_LOCK(c_tmp);
|
||||
FlashIsOnGoing = 1;
|
||||
|
||||
ret = spi_flash_read_raw(&flashchip, src_addr, dest, size);
|
||||
|
||||
FlashIsOnGoing = 0;
|
||||
FLASH_INTR_UNLOCK(c_tmp);
|
||||
|
||||
return ret == 0 ? ESP_OK : ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_read(size_t src_addr, void *dest, size_t size)
|
||||
{
|
||||
#undef FLASH_READ
|
||||
#define FLASH_READ(addr, dest, size) \
|
||||
{ \
|
||||
ret = __spi_flash_read(addr, dest, size); \
|
||||
esp_task_wdt_reset(); \
|
||||
if (ret) \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
esp_err_t ret;
|
||||
uint8_t *tmp = (uint8_t *)dest;
|
||||
|
||||
if (!size)
|
||||
return ESP_OK;
|
||||
|
||||
if (tmp == NULL) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if (NOT_ALIGN(src_addr)
|
||||
|| NOT_ALIGN(tmp)
|
||||
|| NOT_ALIGN(size)) {
|
||||
uint8_t buf[SPI_READ_BUF_MAX];
|
||||
|
||||
if (NOT_ALIGN(src_addr)) {
|
||||
size_t r_addr = FLASH_ALIGN_BEFORE(src_addr);
|
||||
size_t c_off = src_addr - r_addr;
|
||||
size_t wbytes = FLASH_ALIGN_BYTES - c_off;
|
||||
|
||||
wbytes = wbytes > size ? size : wbytes;
|
||||
|
||||
FLASH_READ(r_addr, buf, FLASH_ALIGN_BYTES);
|
||||
memcpy(tmp, &buf[c_off], wbytes);
|
||||
|
||||
tmp += wbytes;
|
||||
src_addr += wbytes;
|
||||
size -= wbytes;
|
||||
}
|
||||
|
||||
while (size) {
|
||||
size_t len = size >= SPI_READ_BUF_MAX ? SPI_READ_BUF_MAX : size;
|
||||
size_t wlen = FLASH_ALIGN(len);
|
||||
|
||||
FLASH_READ(src_addr, buf, wlen);
|
||||
|
||||
memcpy(tmp, buf, len);
|
||||
|
||||
src_addr += len;
|
||||
tmp += len;
|
||||
size -= len;
|
||||
}
|
||||
} else {
|
||||
FLASH_READ(src_addr, tmp, size);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erase a range of flash sectors
|
||||
*/
|
||||
esp_err_t spi_flash_erase_range(size_t start_address, size_t size)
|
||||
{
|
||||
esp_err_t ret;
|
||||
size_t sec, num;
|
||||
|
||||
if (start_address % SPI_FLASH_SEC_SIZE
|
||||
|| size % SPI_FLASH_SEC_SIZE) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if (spi_flash_check_wr_protect() == false) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
sec = start_address / SPI_FLASH_SEC_SIZE;
|
||||
num = size / SPI_FLASH_SEC_SIZE;
|
||||
|
||||
/*
|
||||
* call "spi_flash_erase_sector" continuely to make the function to be able
|
||||
* to enter/exit critical state so that system core can feed watch
|
||||
*/
|
||||
do {
|
||||
ret = spi_flash_erase_sector(sec++);
|
||||
|
||||
esp_task_wdt_reset();
|
||||
} while (ret == ESP_OK && --num);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void esp_spi_flash_init(uint32_t spi_speed, uint32_t spi_mode)
|
||||
{
|
||||
uint32_t freqdiv, freqbits;
|
||||
|
||||
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_USRREG, BIT5);
|
||||
|
||||
if (spi_speed < 3)
|
||||
freqdiv = spi_speed + 2;
|
||||
else if (0x0F == spi_speed)
|
||||
freqdiv = 1;
|
||||
else
|
||||
freqdiv = 2;
|
||||
|
||||
if (1 >= freqdiv) {
|
||||
freqbits = SPI_FLASH_CLK_EQU_SYSCLK;
|
||||
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL, SPI_FLASH_CLK_EQU_SYSCLK);
|
||||
SET_PERI_REG_MASK(PERIPHS_IO_MUX_CONF_U, SPI0_CLK_EQU_SYSCLK);
|
||||
} else {
|
||||
freqbits = ((freqdiv - 1) << 8) + ((freqdiv / 2 - 1) << 4) + (freqdiv - 1);
|
||||
CLEAR_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL, SPI_FLASH_CLK_EQU_SYSCLK);
|
||||
CLEAR_PERI_REG_MASK(PERIPHS_IO_MUX_CONF_U, SPI0_CLK_EQU_SYSCLK);
|
||||
}
|
||||
SET_PERI_REG_BITS(PERIPHS_SPI_FLASH_CTRL, 0xfff, freqbits, 0);
|
||||
|
||||
if (spi_mode == ESP_IMAGE_SPI_MODE_QIO || spi_mode == ESP_IMAGE_SPI_MODE_QOUT) {
|
||||
user_spi_flash_dio_to_qio_pre_init();
|
||||
|
||||
ESP_EARLY_LOGI("qio_mode", "Enabling default flash chip QIO");
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t spi_flash_cache2phys(const void *cached)
|
||||
{
|
||||
uint32_t map_size;
|
||||
uintptr_t addr_offset;
|
||||
uintptr_t addr = (uintptr_t)cached;
|
||||
|
||||
const uint32_t reg = REG_READ(CACHE_FLASH_CTRL_REG);
|
||||
const uint32_t segment = (reg >> CACHE_MAP_SEGMENT_S) & CACHE_MAP_SEGMENT_MASK;
|
||||
|
||||
if (reg & CACHE_MAP_2M) {
|
||||
map_size = CACHE_2M_SIZE;
|
||||
addr_offset = 0;
|
||||
} else {
|
||||
map_size = CACHE_1M_SIZE;
|
||||
if (reg & CACHE_MAP_1M_HIGH)
|
||||
addr_offset = CACHE_1M_SIZE;
|
||||
else
|
||||
addr_offset = 0;
|
||||
}
|
||||
|
||||
if (addr <= CACHE_BASE_ADDR || addr >= CACHE_BASE_ADDR + map_size)
|
||||
return SPI_FLASH_CACHE2PHYS_FAIL;
|
||||
|
||||
return segment * CACHE_2M_SIZE + (addr + addr_offset - CACHE_BASE_ADDR);
|
||||
}
|
290
cpu/esp8266/vendor/esp-idf/spi_flash/spi_flash_raw.c
vendored
Normal file
290
cpu/esp8266/vendor/esp-idf/spi_flash/spi_flash_raw.c
vendored
Normal file
@ -0,0 +1,290 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "spi_flash.h"
|
||||
#include "priv/esp_spi_flash_raw.h"
|
||||
|
||||
#include "esp8266/eagle_soc.h"
|
||||
#include "esp8266/pin_mux_register.h"
|
||||
#include "esp8266/spi_register.h"
|
||||
|
||||
void Cache_Read_Disable_2(void)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(CACHE_FLASH_CTRL_REG,CACHE_READ_EN_BIT);
|
||||
while(REG_READ(SPI_EXT2(0)) != 0) { }
|
||||
CLEAR_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL,SPI_ENABLE_AHB);
|
||||
}
|
||||
|
||||
void Cache_Read_Enable_2(void)
|
||||
{
|
||||
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL,SPI_ENABLE_AHB);
|
||||
SET_PERI_REG_MASK(CACHE_FLASH_CTRL_REG,CACHE_READ_EN_BIT);
|
||||
}
|
||||
void Cache_Read_Enable_New(void) __attribute__((alias("Cache_Read_Enable_2")));
|
||||
|
||||
uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip)
|
||||
{
|
||||
uint32_t rdid = 0;
|
||||
|
||||
Cache_Read_Disable();
|
||||
|
||||
Wait_SPI_Idle(chip);
|
||||
|
||||
WRITE_PERI_REG(PERIPHS_SPI_FLASH_C0, 0); // clear regisrter
|
||||
WRITE_PERI_REG(PERIPHS_SPI_FLASH_CMD, SPI_FLASH_RDID);
|
||||
while(READ_PERI_REG(PERIPHS_SPI_FLASH_CMD)!=0);
|
||||
|
||||
rdid = READ_PERI_REG(PERIPHS_SPI_FLASH_C0)&0xffffff;
|
||||
|
||||
Cache_Read_Enable_New();
|
||||
|
||||
return rdid;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
Cache_Read_Disable_2();
|
||||
|
||||
ret = SPI_read_status(chip, status);
|
||||
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status_value)
|
||||
{
|
||||
Cache_Read_Disable_2();
|
||||
|
||||
Wait_SPI_Idle(chip);
|
||||
|
||||
if (ESP_OK != SPI_write_enable(chip))
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
|
||||
if(ESP_OK != SPI_write_status(chip, status_value))
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
|
||||
Wait_SPI_Idle(chip);
|
||||
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, size_t sec_size)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
Cache_Read_Disable_2();
|
||||
|
||||
if (ESP_OK != SPI_write_enable(chip)) {
|
||||
ret = ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
if (ESP_OK != SPI_sector_erase(chip, sec * sec_size)) {
|
||||
ret = ESP_ERR_FLASH_OP_FAIL;
|
||||
}
|
||||
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
Cache_Read_Disable_2();
|
||||
|
||||
ret = Enable_QMode(chip);
|
||||
|
||||
Wait_SPI_Idle(chip);
|
||||
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, const void *src, size_t size)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
Cache_Read_Disable_2();
|
||||
|
||||
ret = SPI_page_program(chip, dest_addr, (void *)src, size);
|
||||
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void *dest, size_t size)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
Cache_Read_Disable_2();
|
||||
|
||||
ret = SPI_read_data(chip, src_addr, dest, size);
|
||||
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool spi_user_cmd_raw(esp_spi_flash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd)
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
// Cache Disable
|
||||
Cache_Read_Disable_2();
|
||||
//wait spi idle
|
||||
if((mode & SPI_RAW) == 0) {
|
||||
Wait_SPI_Idle(chip);
|
||||
}
|
||||
//save reg
|
||||
uint32_t io_mux_reg = READ_PERI_REG(PERIPHS_IO_MUX_CONF_U);
|
||||
uint32_t spi_clk_reg = READ_PERI_REG(SPI_CLOCK(SPI));
|
||||
uint32_t spi_ctrl_reg = READ_PERI_REG(SPI_CTRL(SPI));
|
||||
uint32_t spi_user_reg = READ_PERI_REG(SPI_USER(SPI));
|
||||
|
||||
if (mode & SPI_WRSR) {
|
||||
// enable write register
|
||||
SPI_write_enable(chip);
|
||||
}
|
||||
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI),SPI_USR_COMMAND);
|
||||
|
||||
//Disable flash operation mode
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_FLASH_MODE);
|
||||
//SET SPI SEND BUFFER MODE
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MISO_HIGHPART);
|
||||
//CLEAR EQU SYS CLK
|
||||
CLEAR_PERI_REG_MASK(PERIPHS_IO_MUX_CONF_U,SPI0_CLK_EQU_SYS_CLK);
|
||||
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI), SPI_CS_SETUP|SPI_CS_HOLD|SPI_USR_COMMAND|SPI_USR_MOSI);
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_FLASH_MODE);
|
||||
//CLEAR DAUL OR QUAD LINES TRANSMISSION MODE
|
||||
CLEAR_PERI_REG_MASK(SPI_CTRL(SPI), SPI_QIO_MODE|SPI_DIO_MODE|SPI_DOUT_MODE|SPI_QOUT_MODE);
|
||||
WRITE_PERI_REG(SPI_CLOCK(SPI),
|
||||
((3&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
|
||||
((1&SPI_CLKCNT_H)<<SPI_CLKCNT_H_S)|
|
||||
((3&SPI_CLKCNT_L)<<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div
|
||||
//Enable fast read mode
|
||||
SET_PERI_REG_MASK(SPI_CTRL(SPI), SPI_FASTRD_MODE);
|
||||
|
||||
//WAIT COMMAND DONE
|
||||
while(READ_PERI_REG(SPI_CMD(SPI)) & SPI_USR);
|
||||
|
||||
//SET USER CMD
|
||||
if (p_cmd->cmd_len != 0) {
|
||||
//Max CMD length is 16 bits
|
||||
SET_PERI_REG_BITS(SPI_USER2(SPI), SPI_USR_COMMAND_BITLEN, p_cmd->cmd_len * 8 - 1, SPI_USR_COMMAND_BITLEN_S);
|
||||
//Enable CMD
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_COMMAND);
|
||||
//LOAD CMD
|
||||
SET_PERI_REG_BITS(SPI_USER2(SPI), SPI_USR_COMMAND_VALUE, p_cmd->cmd, SPI_USR_COMMAND_VALUE_S);
|
||||
} else {
|
||||
//CLEAR CMD
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_COMMAND);
|
||||
SET_PERI_REG_BITS(SPI_USER2(SPI), SPI_USR_COMMAND_BITLEN, 0, SPI_USR_COMMAND_BITLEN_S);
|
||||
}
|
||||
if (p_cmd->dummy_bits != 0) {
|
||||
//SET dummy bits
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_DUMMY_CYCLELEN, p_cmd->dummy_bits - 1, SPI_USR_DUMMY_CYCLELEN_S);
|
||||
//Enable dummy
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_DUMMY);
|
||||
} else {
|
||||
//CLEAR DUMMY
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_DUMMY_CYCLELEN, 0, SPI_USR_DUMMY_CYCLELEN_S);
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_DUMMY);
|
||||
}
|
||||
|
||||
//SET USER ADDRESS
|
||||
if (p_cmd->addr_len != 0) {
|
||||
//Set addr lenght
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_ADDR_BITLEN, p_cmd->addr_len * 8 - 1, SPI_USR_ADDR_BITLEN_S);
|
||||
//Enable user address
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_ADDR);
|
||||
WRITE_PERI_REG(SPI_ADDR(SPI), *p_cmd->addr);
|
||||
} else {
|
||||
//CLEAR ADDR
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_ADDR);
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_ADDR_BITLEN, 0, SPI_USR_ADDR_BITLEN_S);
|
||||
}
|
||||
|
||||
uint32_t *value = p_cmd->data;
|
||||
if (((mode & SPI_TX) || (mode & SPI_WRSR)) && p_cmd->data_len != 0) {
|
||||
//Enable MOSI, disable MISO
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MOSI);
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MISO);
|
||||
do {
|
||||
WRITE_PERI_REG((SPI_W0(SPI) + (idx << 2)), *value++);
|
||||
} while ( ++idx < (p_cmd->data_len / 4));
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_MOSI_BITLEN, ((p_cmd->data_len) * 8 - 1), SPI_USR_MOSI_BITLEN_S);
|
||||
|
||||
} else if ((mode & SPI_RX) && p_cmd->data_len != 0) {
|
||||
//Enable MISO, disable MOSI
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MOSI);
|
||||
SET_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MISO);
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI),SPI_USR_MISO_BITLEN, p_cmd->data_len * 8 - 1, SPI_USR_MISO_BITLEN_S);
|
||||
int fifo_idx = 0;
|
||||
do {
|
||||
WRITE_PERI_REG((SPI_W0(SPI) + (fifo_idx << 2)), 0);
|
||||
} while ( ++fifo_idx < (p_cmd->data_len / 4));
|
||||
} else {
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MOSI);
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(SPI), SPI_USR_MISO);
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_MISO_BITLEN, 0, SPI_USR_MISO_BITLEN_S);
|
||||
SET_PERI_REG_BITS(SPI_USER1(SPI), SPI_USR_MOSI_BITLEN, 0, SPI_USR_MOSI_BITLEN_S);
|
||||
}
|
||||
|
||||
//Start command
|
||||
SET_PERI_REG_MASK(SPI_CMD(SPI), SPI_USR);
|
||||
while (READ_PERI_REG(SPI_CMD(SPI)) & SPI_USR);
|
||||
|
||||
if (mode & SPI_RX) {
|
||||
do {
|
||||
*p_cmd->data ++ = READ_PERI_REG(SPI_W0(SPI) + (idx << 2));
|
||||
} while (++idx < (p_cmd->data_len / 4));
|
||||
}
|
||||
|
||||
//recover
|
||||
WRITE_PERI_REG(PERIPHS_IO_MUX_CONF_U,io_mux_reg);
|
||||
WRITE_PERI_REG(SPI_CTRL(SPI),spi_ctrl_reg);
|
||||
WRITE_PERI_REG(SPI_CLOCK(SPI),spi_clk_reg);
|
||||
WRITE_PERI_REG(SPI_USER(SPI),spi_user_reg);
|
||||
|
||||
if((mode & SPI_RAW) == 0) {
|
||||
Wait_SPI_Idle(chip);
|
||||
}
|
||||
//enable icache
|
||||
Cache_Read_Enable_2();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void spi_flash_switch_to_qio_raw(void)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL, SPI_QIO_MODE
|
||||
|SPI_QOUT_MODE
|
||||
|SPI_DIO_MODE
|
||||
|SPI_DOUT_MODE
|
||||
|SPI_FASTRD_MODE);
|
||||
|
||||
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL, SPI_QIO_MODE | SPI_FASTRD_MODE);
|
||||
}
|
5
cpu/esp8266/vendor/esp-idf/util/src/Makefile
vendored
Normal file
5
cpu/esp8266/vendor/esp-idf/util/src/Makefile
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
MODULE=esp_idf_util
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/util/include
|
144
cpu/esp8266/vendor/esp-idf/util/src/crc.c
vendored
Normal file
144
cpu/esp8266/vendor/esp-idf/util/src/crc.c
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
static const uint32_t crc32_le_table[256] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
|
||||
0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
|
||||
0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
|
||||
0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
|
||||
0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
|
||||
0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
|
||||
0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
|
||||
0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
|
||||
0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
|
||||
0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
|
||||
0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
|
||||
0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
|
||||
0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
|
||||
|
||||
0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
|
||||
0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
|
||||
0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
|
||||
0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
|
||||
0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
|
||||
0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
|
||||
0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
|
||||
0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
|
||||
0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
|
||||
0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
|
||||
0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
|
||||
0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
|
||||
0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
|
||||
};
|
||||
|
||||
static const uint16_t crc16_le_table[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
static const uint8_t crc8_le_table[] = {
|
||||
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
|
||||
0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc,
|
||||
0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62,
|
||||
0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff,
|
||||
0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07,
|
||||
0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a,
|
||||
0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24,
|
||||
0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9,
|
||||
0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd,
|
||||
0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50,
|
||||
0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee,
|
||||
0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73,
|
||||
0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b,
|
||||
0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16,
|
||||
0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8,
|
||||
0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35
|
||||
};
|
||||
|
||||
uint16_t crc16_le(uint16_t crc, const uint8_t* buf, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
crc = ~crc;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
crc = crc16_le_table[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);
|
||||
}
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
uint32_t crc32_le(uint32_t crc, const uint8_t* buf, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
crc = ~crc;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
crc = crc32_le_table[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);
|
||||
}
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
uint8_t esp_crc8(uint8_t const* p, uint32_t len)
|
||||
{
|
||||
uint8_t crc = 0x00;
|
||||
|
||||
while (len--) {
|
||||
crc = crc8_le_table[crc ^ *p++];
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
22
cpu/esp8266/vendor/esp-idf/wpa_supplicant/COPYING
vendored
Normal file
22
cpu/esp8266/vendor/esp-idf/wpa_supplicant/COPYING
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
wpa_supplicant and hostapd
|
||||
--------------------------
|
||||
|
||||
Copyright (c) 2002-2016, Jouni Malinen <j@w1.fi> and contributors
|
||||
All Rights Reserved.
|
||||
|
||||
|
||||
See the README file for the current license terms.
|
||||
|
||||
This software was previously distributed under BSD/GPL v2 dual license
|
||||
terms that allowed either of those license alternatives to be
|
||||
selected. As of February 11, 2012, the project has chosen to use only
|
||||
the BSD license option for future distribution. As such, the GPL v2
|
||||
license option is no longer used. It should be noted that the BSD
|
||||
license option (the one with advertisement clause removed) is compatible
|
||||
with GPL and as such, does not prevent use of this software in projects
|
||||
that use GPL.
|
||||
|
||||
Some of the files may still include pointers to GPL version 2 license
|
||||
terms. However, such copyright and license notifications are maintained
|
||||
only for attribution purposes and any distribution of this software
|
||||
after February 11, 2012 is no longer under the GPL v2 option.
|
9
cpu/esp8266/vendor/esp-idf/wpa_supplicant/Makefile
vendored
Normal file
9
cpu/esp8266/vendor/esp-idf/wpa_supplicant/Makefile
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
ifneq (,$(filter esp_idf_wpa_supplicant_port ,$(USEMODULE)))
|
||||
DIRS += port
|
||||
endif
|
||||
|
||||
ifneq (,$(filter esp_idf_wpa_supplicant_crypto ,$(USEMODULE)))
|
||||
DIRS += src/crypto
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
35
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/aes.h
vendored
Normal file
35
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/aes.h
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* AES functions
|
||||
* Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
void *wpa_aes_encrypt_init(const u8 *key, size_t len);
|
||||
void wpa_aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
|
||||
void wpa_aes_encrypt_deinit(void *ctx);
|
||||
void *wpa_aes_decrypt_init(const u8 *key, size_t len);
|
||||
void wpa_aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
|
||||
void wpa_aes_decrypt_deinit(void *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AES_H */
|
139
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/aes_i.h
vendored
Normal file
139
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/aes_i.h
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_I_H
|
||||
#define AES_I_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "aes.h"
|
||||
|
||||
/* #define FULL_UNROLL */
|
||||
#define AES_SMALL_TABLES
|
||||
|
||||
extern const u32 Te0[256];
|
||||
extern const u32 Te1[256];
|
||||
extern const u32 Te2[256];
|
||||
extern const u32 Te3[256];
|
||||
extern const u32 Te4[256];
|
||||
extern const u32 Td0[256];
|
||||
extern const u32 Td1[256];
|
||||
extern const u32 Td2[256];
|
||||
extern const u32 Td3[256];
|
||||
extern const u32 Td4[256];
|
||||
extern const u32 rcon[10];
|
||||
extern const u8 Td4s[256];
|
||||
extern const u8 rcons[10];
|
||||
|
||||
#ifndef AES_SMALL_TABLES
|
||||
|
||||
#define RCON(i) rcon[(i)]
|
||||
|
||||
#define TE0(i) Te0[((i) >> 24) & 0xff]
|
||||
#define TE1(i) Te1[((i) >> 16) & 0xff]
|
||||
#define TE2(i) Te2[((i) >> 8) & 0xff]
|
||||
#define TE3(i) Te3[(i) & 0xff]
|
||||
#define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
|
||||
#define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
|
||||
#define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
|
||||
#define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
|
||||
#define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
|
||||
#define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
|
||||
#define TE411(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
|
||||
#define TE422(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE433(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE444(i) (Te4[(i) & 0xff] & 0x000000ff)
|
||||
#define TE4(i) (Te4[(i)] & 0x000000ff)
|
||||
|
||||
#define TD0(i) Td0[((i) >> 24) & 0xff]
|
||||
#define TD1(i) Td1[((i) >> 16) & 0xff]
|
||||
#define TD2(i) Td2[((i) >> 8) & 0xff]
|
||||
#define TD3(i) Td3[(i) & 0xff]
|
||||
#define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
|
||||
#define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
|
||||
#define TD0_(i) Td0[(i) & 0xff]
|
||||
#define TD1_(i) Td1[(i) & 0xff]
|
||||
#define TD2_(i) Td2[(i) & 0xff]
|
||||
#define TD3_(i) Td3[(i) & 0xff]
|
||||
|
||||
#else /* AES_SMALL_TABLES */
|
||||
|
||||
#define RCON(i) (rcons[(i)] << 24)
|
||||
|
||||
static inline u32 rotr(u32 val, int bits)
|
||||
{
|
||||
return (val >> bits) | (val << (32 - bits));
|
||||
}
|
||||
|
||||
#define TE0(i) Te0[((i) >> 24) & 0xff]
|
||||
#define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
|
||||
#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
|
||||
#define TE3(i) rotr(Te0[(i) & 0xff], 24)
|
||||
#define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
|
||||
#define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
|
||||
#define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
|
||||
#define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
|
||||
#define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
|
||||
#define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
|
||||
#define TE411(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
|
||||
#define TE422(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE433(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE444(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
|
||||
#define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
|
||||
|
||||
#define TD0(i) Td0[((i) >> 24) & 0xff]
|
||||
#define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
|
||||
#define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
|
||||
#define TD3(i) rotr(Td0[(i) & 0xff], 24)
|
||||
#define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
|
||||
#define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
|
||||
#define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
|
||||
#define TD44(i) (Td4s[(i) & 0xff])
|
||||
#define TD0_(i) Td0[(i) & 0xff]
|
||||
#define TD1_(i) rotr(Td0[(i) & 0xff], 8)
|
||||
#define TD2_(i) rotr(Td0[(i) & 0xff], 16)
|
||||
#define TD3_(i) rotr(Td0[(i) & 0xff], 24)
|
||||
|
||||
#endif /* AES_SMALL_TABLES */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
|
||||
#define GETU32(p) SWAP(*((u32 *)(p)))
|
||||
#define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
|
||||
#else
|
||||
#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
|
||||
((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
||||
#define PUTU32(ct, st) { \
|
||||
(ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
|
||||
(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
||||
#endif
|
||||
|
||||
#define AES_PRIV_SIZE (4 * 4 * 15 + 4)
|
||||
#define AES_PRIV_NR_POS (4 * 15)
|
||||
|
||||
int wpa_rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AES_I_H */
|
56
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/aes_wrap.h
vendored
Normal file
56
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/aes_wrap.h
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* AES-based functions
|
||||
*
|
||||
* - AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
|
||||
* - One-Key CBC MAC (OMAC1) hash with AES-128
|
||||
* - AES-128 CTR mode encryption
|
||||
* - AES-128 EAX mode encryption/decryption
|
||||
* - AES-128 CBC
|
||||
*
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_WRAP_H
|
||||
#define AES_WRAP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int __must_check wpa_aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher);
|
||||
int __must_check wpa_aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain);
|
||||
int __must_check wpa_omac1_aes_128_vector(const u8 *key, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len,
|
||||
u8 *mac);
|
||||
int __must_check omac1_aes_128(const u8 *key, const u8 *data, size_t data_len,
|
||||
u8 *mac);
|
||||
int __must_check aes_128_encrypt_block(const u8 *key, const u8 *in, u8 *out);
|
||||
int __must_check aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
|
||||
u8 *data, size_t data_len);
|
||||
int __must_check aes_128_eax_encrypt(const u8 *key,
|
||||
const u8 *nonce, size_t nonce_len,
|
||||
const u8 *hdr, size_t hdr_len,
|
||||
u8 *data, size_t data_len, u8 *tag);
|
||||
int __must_check aes_128_eax_decrypt(const u8 *key,
|
||||
const u8 *nonce, size_t nonce_len,
|
||||
const u8 *hdr, size_t hdr_len,
|
||||
u8 *data, size_t data_len, const u8 *tag);
|
||||
int __must_check aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
int __must_check aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AES_WRAP_H */
|
31
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/base64.h
vendored
Normal file
31
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/base64.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Base64 encoding/decoding (RFC1341)
|
||||
* Copyright (c) 2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef BASE64_H
|
||||
#define BASE64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
size_t *out_len);
|
||||
unsigned char * base64_decode(const unsigned char *src, size_t len,
|
||||
size_t *out_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BASE64_H */
|
489
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/common.h
vendored
Normal file
489
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/common.h
vendored
Normal file
@ -0,0 +1,489 @@
|
||||
/*
|
||||
* wpa_supplicant/hostapd / common helper functions, etc.
|
||||
* Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#if defined(__XTENSA__)
|
||||
#include <machine/endian.h>
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#endif /*__XTENSA__*/
|
||||
|
||||
#if defined(__linux__) || defined(__GLIBC__)
|
||||
#include <endian.h>
|
||||
#include <byteswap.h>
|
||||
#endif /* __linux__ */
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
|
||||
defined(__OpenBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/endian.h>
|
||||
#define __BYTE_ORDER _BYTE_ORDER
|
||||
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
|
||||
#define __BIG_ENDIAN _BIG_ENDIAN
|
||||
#ifdef __OpenBSD__
|
||||
#define bswap_16 swap16
|
||||
#define bswap_32 swap32
|
||||
#define bswap_64 swap64
|
||||
#else /* __OpenBSD__ */
|
||||
#define bswap_16 bswap16
|
||||
#define bswap_32 bswap32
|
||||
#define bswap_64 bswap64
|
||||
#endif /* __OpenBSD__ */
|
||||
#endif /* defined(__FreeBSD__) || defined(__NetBSD__) ||
|
||||
* defined(__DragonFly__) || defined(__OpenBSD__) */
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/types.h>
|
||||
#include <machine/endian.h>
|
||||
#define __BYTE_ORDER _BYTE_ORDER
|
||||
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
|
||||
#define __BIG_ENDIAN _BIG_ENDIAN
|
||||
static inline unsigned short bswap_16(unsigned short v)
|
||||
{
|
||||
return ((v & 0xff) << 8) | (v >> 8);
|
||||
}
|
||||
|
||||
static inline unsigned int bswap_32(unsigned int v)
|
||||
{
|
||||
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
|
||||
((v & 0xff0000) >> 8) | (v >> 24);
|
||||
}
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#ifdef CONFIG_TI_COMPILER
|
||||
#define __BIG_ENDIAN 4321
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#ifdef __big_endian__
|
||||
#define __BYTE_ORDER __BIG_ENDIAN
|
||||
#else
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
#endif
|
||||
#endif /* CONFIG_TI_COMPILER */
|
||||
|
||||
#ifdef __SYMBIAN32__
|
||||
#define __BIG_ENDIAN 4321
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
#endif /* __SYMBIAN32__ */
|
||||
|
||||
#ifdef CONFIG_NATIVE_WINDOWS
|
||||
#include <winsock.h>
|
||||
|
||||
typedef int socklen_t;
|
||||
|
||||
#ifndef MSG_DONTWAIT
|
||||
#define MSG_DONTWAIT 0 /* not supported */
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NATIVE_WINDOWS */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define inline __inline
|
||||
|
||||
#undef vsnprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#undef close
|
||||
#define close closesocket
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
|
||||
/* Define platform specific integer types */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
typedef UINT64 u64;
|
||||
typedef UINT32 u32;
|
||||
typedef UINT16 u16;
|
||||
typedef UINT8 u8;
|
||||
typedef INT64 s64;
|
||||
typedef INT32 s32;
|
||||
typedef INT16 s16;
|
||||
typedef INT8 s8;
|
||||
#define WPA_TYPES_DEFINED
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#ifdef __vxworks
|
||||
typedef unsigned long long u64;
|
||||
typedef UINT32 u32;
|
||||
typedef UINT16 u16;
|
||||
typedef UINT8 u8;
|
||||
typedef long long s64;
|
||||
typedef INT32 s32;
|
||||
typedef INT16 s16;
|
||||
typedef INT8 s8;
|
||||
#define WPA_TYPES_DEFINED
|
||||
#endif /* __vxworks */
|
||||
|
||||
#ifdef CONFIG_TI_COMPILER
|
||||
#ifdef _LLONG_AVAILABLE
|
||||
typedef unsigned long long u64;
|
||||
#else
|
||||
/*
|
||||
* TODO: 64-bit variable not available. Using long as a workaround to test the
|
||||
* build, but this will likely not work for all operations.
|
||||
*/
|
||||
typedef unsigned long u64;
|
||||
#endif
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
#define WPA_TYPES_DEFINED
|
||||
#endif /* CONFIG_TI_COMPILER */
|
||||
|
||||
#ifdef __SYMBIAN32__
|
||||
#define __REMOVE_PLATSEC_DIAGNOSTICS__
|
||||
#include <e32def.h>
|
||||
typedef TUint64 u64;
|
||||
typedef TUint32 u32;
|
||||
typedef TUint16 u16;
|
||||
typedef TUint8 u8;
|
||||
#define WPA_TYPES_DEFINED
|
||||
#endif /* __SYMBIAN32__ */
|
||||
|
||||
#ifndef WPA_TYPES_DEFINED
|
||||
#ifdef CONFIG_USE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef uint64_t u64;
|
||||
typedef uint32_t u32;
|
||||
typedef uint16_t u16;
|
||||
typedef uint8_t u8;
|
||||
typedef int64_t s64;
|
||||
typedef int32_t s32;
|
||||
typedef int16_t s16;
|
||||
typedef int8_t s8;
|
||||
#define WPA_TYPES_DEFINED
|
||||
#endif /* !WPA_TYPES_DEFINED */
|
||||
|
||||
|
||||
/* Define platform specific byte swapping macros */
|
||||
|
||||
#if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
|
||||
|
||||
static inline unsigned short wpa_swap_16(unsigned short v)
|
||||
{
|
||||
return ((v & 0xff) << 8) | (v >> 8);
|
||||
}
|
||||
|
||||
static inline unsigned int wpa_swap_32(unsigned int v)
|
||||
{
|
||||
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
|
||||
((v & 0xff0000) >> 8) | (v >> 24);
|
||||
}
|
||||
|
||||
#define le_to_host16(n) (n)
|
||||
#define host_to_le16(n) (n)
|
||||
#define be_to_host16(n) wpa_swap_16(n)
|
||||
#define host_to_be16(n) wpa_swap_16(n)
|
||||
#define le_to_host32(n) (n)
|
||||
#define be_to_host32(n) wpa_swap_32(n)
|
||||
#define host_to_be32(n) wpa_swap_32(n)
|
||||
|
||||
#define WPA_BYTE_SWAP_DEFINED
|
||||
|
||||
#endif /* __CYGWIN__ || CONFIG_NATIVE_WINDOWS */
|
||||
|
||||
|
||||
#ifndef WPA_BYTE_SWAP_DEFINED
|
||||
|
||||
#ifndef __BYTE_ORDER
|
||||
#ifndef __LITTLE_ENDIAN
|
||||
#ifndef __BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#define __BIG_ENDIAN 4321
|
||||
#if defined(sparc)
|
||||
#define __BYTE_ORDER __BIG_ENDIAN
|
||||
#endif
|
||||
#endif /* __BIG_ENDIAN */
|
||||
#endif /* __LITTLE_ENDIAN */
|
||||
#endif /* __BYTE_ORDER */
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define le_to_host16(n) ((__force u16) (le16) (n))
|
||||
#define host_to_le16(n) ((__force le16) (u16) (n))
|
||||
#define be_to_host16(n) bswap_16((__force u16) (be16) (n))
|
||||
#define host_to_be16(n) ((__force be16) bswap_16((n)))
|
||||
#define le_to_host32(n) ((__force u32) (le32) (n))
|
||||
#define host_to_le32(n) ((__force le32) (u32) (n))
|
||||
#define be_to_host32(n) bswap_32((__force u32) (be32) (n))
|
||||
#define host_to_be32(n) ((__force be32) bswap_32((n)))
|
||||
#define le_to_host64(n) ((__force u64) (le64) (n))
|
||||
#define host_to_le64(n) ((__force le64) (u64) (n))
|
||||
#define be_to_host64(n) bswap_64((__force u64) (be64) (n))
|
||||
#define host_to_be64(n) ((__force be64) bswap_64((n)))
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define le_to_host16(n) bswap_16(n)
|
||||
#define host_to_le16(n) bswap_16(n)
|
||||
#define be_to_host16(n) (n)
|
||||
#define host_to_be16(n) (n)
|
||||
#define le_to_host32(n) bswap_32(n)
|
||||
#define be_to_host32(n) (n)
|
||||
#define host_to_be32(n) (n)
|
||||
#define le_to_host64(n) bswap_64(n)
|
||||
#define host_to_le64(n) bswap_64(n)
|
||||
#define be_to_host64(n) (n)
|
||||
#define host_to_be64(n) (n)
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
#define WORDS_BIGENDIAN
|
||||
#endif
|
||||
#else
|
||||
#error Could not determine CPU byte order
|
||||
#endif
|
||||
|
||||
#define WPA_BYTE_SWAP_DEFINED
|
||||
#endif /* !WPA_BYTE_SWAP_DEFINED */
|
||||
|
||||
|
||||
/* Macros for handling unaligned memory accesses */
|
||||
|
||||
#define WPA_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
|
||||
#define WPA_PUT_BE16(a, val) \
|
||||
do { \
|
||||
(a)[0] = ((u16) (val)) >> 8; \
|
||||
(a)[1] = ((u16) (val)) & 0xff; \
|
||||
} while (0)
|
||||
|
||||
#define WPA_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
|
||||
#define WPA_PUT_LE16(a, val) \
|
||||
do { \
|
||||
(a)[1] = ((u16) (val)) >> 8; \
|
||||
(a)[0] = ((u16) (val)) & 0xff; \
|
||||
} while (0)
|
||||
|
||||
#define WPA_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
|
||||
((u32) (a)[2]))
|
||||
#define WPA_PUT_BE24(a, val) \
|
||||
do { \
|
||||
(a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
||||
(a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
||||
(a)[2] = (u8) (((u32) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define WPA_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
|
||||
(((u32) (a)[2]) << 8) | ((u32) (a)[3]))
|
||||
#define WPA_PUT_BE32(a, val) \
|
||||
do { \
|
||||
(a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
|
||||
(a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
||||
(a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
||||
(a)[3] = (u8) (((u32) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define WPA_GET_LE32(a) ((((u32) (a)[3]) << 24) | (((u32) (a)[2]) << 16) | \
|
||||
(((u32) (a)[1]) << 8) | ((u32) (a)[0]))
|
||||
#define WPA_PUT_LE32(a, val) \
|
||||
do { \
|
||||
(a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \
|
||||
(a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
||||
(a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
||||
(a)[0] = (u8) (((u32) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define WPA_GET_BE64(a) ((((u64) (a)[0]) << 56) | (((u64) (a)[1]) << 48) | \
|
||||
(((u64) (a)[2]) << 40) | (((u64) (a)[3]) << 32) | \
|
||||
(((u64) (a)[4]) << 24) | (((u64) (a)[5]) << 16) | \
|
||||
(((u64) (a)[6]) << 8) | ((u64) (a)[7]))
|
||||
#define WPA_PUT_BE64(a, val) \
|
||||
do { \
|
||||
(a)[0] = (u8) (((u64) (val)) >> 56); \
|
||||
(a)[1] = (u8) (((u64) (val)) >> 48); \
|
||||
(a)[2] = (u8) (((u64) (val)) >> 40); \
|
||||
(a)[3] = (u8) (((u64) (val)) >> 32); \
|
||||
(a)[4] = (u8) (((u64) (val)) >> 24); \
|
||||
(a)[5] = (u8) (((u64) (val)) >> 16); \
|
||||
(a)[6] = (u8) (((u64) (val)) >> 8); \
|
||||
(a)[7] = (u8) (((u64) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define WPA_GET_LE64(a) ((((u64) (a)[7]) << 56) | (((u64) (a)[6]) << 48) | \
|
||||
(((u64) (a)[5]) << 40) | (((u64) (a)[4]) << 32) | \
|
||||
(((u64) (a)[3]) << 24) | (((u64) (a)[2]) << 16) | \
|
||||
(((u64) (a)[1]) << 8) | ((u64) (a)[0]))
|
||||
|
||||
|
||||
#ifndef ETH_ALEN
|
||||
#define ETH_ALEN 6
|
||||
#endif
|
||||
#ifndef IFNAMSIZ
|
||||
#define IFNAMSIZ 16
|
||||
#endif
|
||||
#ifndef ETH_P_ALL
|
||||
#define ETH_P_ALL 0x0003
|
||||
#endif
|
||||
#ifndef ETH_P_PAE
|
||||
#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
|
||||
#endif /* ETH_P_PAE */
|
||||
#ifndef ETH_P_EAPOL
|
||||
#define ETH_P_EAPOL ETH_P_PAE
|
||||
#endif /* ETH_P_EAPOL */
|
||||
#ifndef ETH_P_RSN_PREAUTH
|
||||
#define ETH_P_RSN_PREAUTH 0x88c7
|
||||
#endif /* ETH_P_RSN_PREAUTH */
|
||||
#ifndef ETH_P_RRB
|
||||
#define ETH_P_RRB 0x890D
|
||||
#endif /* ETH_P_RRB */
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
|
||||
#define STRUCT_PACKED __attribute__ ((packed))
|
||||
#else
|
||||
#define PRINTF_FORMAT(a,b)
|
||||
#define STRUCT_PACKED
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ANSI_C_EXTRA
|
||||
|
||||
#if !defined(_MSC_VER) || _MSC_VER < 1400
|
||||
/* snprintf - used in number of places; sprintf() is _not_ a good replacement
|
||||
* due to possible buffer overflow; see, e.g.,
|
||||
* http://www.ijs.si/software/snprintf/ for portable implementation of
|
||||
* snprintf. */
|
||||
int snprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
/* vsnprintf - only used for wpa_msg() in wpa_supplicant.c */
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
||||
#endif /* !defined(_MSC_VER) || _MSC_VER < 1400 */
|
||||
|
||||
/* getopt - only used in main.c */
|
||||
int getopt(int argc, char *const argv[], const char *optstring);
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
#ifndef CONFIG_NO_SOCKLEN_T_TYPEDEF
|
||||
#ifndef __socklen_t_defined
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* inline - define as __inline or just define it to be empty, if needed */
|
||||
#ifdef CONFIG_NO_INLINE
|
||||
#define inline
|
||||
#else
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#ifndef __func__
|
||||
#define __func__ "__func__ not defined"
|
||||
#endif
|
||||
|
||||
#ifndef bswap_16
|
||||
#define bswap_16(a) ((((u16) (a) << 8) & 0xff00) | (((u16) (a) >> 8) & 0xff))
|
||||
#endif
|
||||
|
||||
#ifndef bswap_32
|
||||
#define bswap_32(a) ((((u32) (a) << 24) & 0xff000000) | \
|
||||
(((u32) (a) << 8) & 0xff0000) | \
|
||||
(((u32) (a) >> 8) & 0xff00) | \
|
||||
(((u32) (a) >> 24) & 0xff))
|
||||
#endif
|
||||
|
||||
#ifndef MSG_DONTWAIT
|
||||
#define MSG_DONTWAIT 0
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
void perror(const char *s);
|
||||
#endif /* _WIN32_WCE */
|
||||
|
||||
#endif /* CONFIG_ANSI_C_EXTRA */
|
||||
|
||||
#ifndef MAC2STR
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
|
||||
#ifndef BIT
|
||||
#define BIT(x) (1 << (x))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Definitions for sparse validation
|
||||
* (http://kernel.org/pub/linux/kernel/people/josh/sparse/)
|
||||
*/
|
||||
#ifdef __CHECKER__
|
||||
#define __force __attribute__((force))
|
||||
#define __bitwise __attribute__((bitwise))
|
||||
#else
|
||||
#define __force
|
||||
#define __bitwise
|
||||
#endif
|
||||
|
||||
typedef u16 __bitwise be16;
|
||||
typedef u16 __bitwise le16;
|
||||
typedef u32 __bitwise be32;
|
||||
typedef u32 __bitwise le32;
|
||||
typedef u64 __bitwise be64;
|
||||
typedef u64 __bitwise le64;
|
||||
|
||||
#ifndef __must_check
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||
#define __must_check __attribute__((__warn_unused_result__))
|
||||
#else
|
||||
#define __must_check
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* __must_check */
|
||||
|
||||
int hwaddr_aton(const char *txt, u8 *addr);
|
||||
int hwaddr_aton2(const char *txt, u8 *addr);
|
||||
int hexstr2bin(const char *hex, u8 *buf, size_t len);
|
||||
void inc_byte_array(u8 *counter, size_t len);
|
||||
void wpa_get_ntp_timestamp(u8 *buf);
|
||||
int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len);
|
||||
int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data,
|
||||
size_t len);
|
||||
|
||||
#ifdef CONFIG_NATIVE_WINDOWS
|
||||
void wpa_unicode2ascii_inplace(TCHAR *str);
|
||||
TCHAR * wpa_strdup_tchar(const char *str);
|
||||
#else /* CONFIG_NATIVE_WINDOWS */
|
||||
#define wpa_unicode2ascii_inplace(s) do { } while (0)
|
||||
#define wpa_strdup_tchar(s) strdup((s))
|
||||
#endif /* CONFIG_NATIVE_WINDOWS */
|
||||
|
||||
const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
|
||||
|
||||
static inline int is_zero_ether_addr(const u8 *a)
|
||||
{
|
||||
return !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]);
|
||||
}
|
||||
|
||||
/*
|
||||
* gcc 4.4 ends up generating strict-aliasing warnings about some very common
|
||||
* networking socket uses that do not really result in a real problem and
|
||||
* cannot be easily avoided with union-based type-punning due to struct
|
||||
* definitions including another struct in system header files. To avoid having
|
||||
* to fully disable strict-aliasing warnings, provide a mechanism to hide the
|
||||
* typecast from aliasing for now. A cleaner solution will hopefully be found
|
||||
* in the future to handle these cases.
|
||||
*/
|
||||
void * __hide_aliasing_typecast(void *foo);
|
||||
#define aliasing_hide_typecast(a,t) (t *) __hide_aliasing_typecast((a))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_H */
|
480
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/crypto.h
vendored
Normal file
480
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/crypto.h
vendored
Normal file
@ -0,0 +1,480 @@
|
||||
/*
|
||||
* WPA Supplicant / wrapper functions for crypto libraries
|
||||
* Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*
|
||||
* This file defines the cryptographic functions that need to be implemented
|
||||
* for wpa_supplicant and hostapd. When TLS is not used, internal
|
||||
* implementation of MD5, SHA1, and AES is used and no external libraries are
|
||||
* required. When TLS is enabled (e.g., by enabling EAP-TLS or EAP-PEAP), the
|
||||
* crypto library used by the TLS implementation is expected to be used for
|
||||
* non-TLS needs, too, in order to save space by not implementing these
|
||||
* functions twice.
|
||||
*
|
||||
* Wrapper code for using each crypto library is in its own file (crypto*.c)
|
||||
* and one of these files is build and linked in to provide the functions
|
||||
* defined here.
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* md4_vector - MD4 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
|
||||
*/
|
||||
int wpa_md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
|
||||
|
||||
/**
|
||||
* md5_vector - 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
|
||||
*/
|
||||
int wpa_md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
|
||||
|
||||
#ifdef CONFIG_FIPS
|
||||
/**
|
||||
* md5_vector_non_fips_allow - MD5 hash for data vector (non-FIPS use allowed)
|
||||
* @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
|
||||
*/
|
||||
int wpa_md5_vector_non_fips_allow(size_t num_elem, const u8 *addr[],
|
||||
const size_t *len, u8 *mac);
|
||||
#else /* CONFIG_FIPS */
|
||||
#define md5_vector_non_fips_allow md5_vector
|
||||
#endif /* CONFIG_FIPS */
|
||||
|
||||
|
||||
/**
|
||||
* sha1_vector - 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
|
||||
*/
|
||||
int wpa_sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *mac);
|
||||
|
||||
/**
|
||||
* fips186_2-prf - NIST FIPS Publication 186-2 change notice 1 PRF
|
||||
* @seed: Seed/key for the PRF
|
||||
* @seed_len: Seed length in bytes
|
||||
* @x: Buffer for PRF output
|
||||
* @xlen: Output length in bytes
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function implements random number generation specified in NIST FIPS
|
||||
* Publication 186-2 for EAP-SIM. This PRF uses a function that is similar to
|
||||
* SHA-1, but has different message padding.
|
||||
*/
|
||||
int __must_check wpa_fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x,
|
||||
size_t xlen);
|
||||
|
||||
/**
|
||||
* sha256_vector - SHA256 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
|
||||
*/
|
||||
int wpa_sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *mac);
|
||||
|
||||
/**
|
||||
* des_encrypt - Encrypt one block with DES
|
||||
* @clear: 8 octets (in)
|
||||
* @key: 7 octets (in) (no parity bits included)
|
||||
* @cypher: 8 octets (out)
|
||||
*/
|
||||
void wpa_des_encrypt(const u8 *clear, const u8 *key, u8 *cypher);
|
||||
|
||||
/**
|
||||
* aes_encrypt_init - 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
|
||||
*/
|
||||
void * wpa_aes_encrypt_init(const u8 *key, size_t len);
|
||||
|
||||
/**
|
||||
* aes_encrypt - 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)
|
||||
*/
|
||||
void wpa_aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
|
||||
|
||||
/**
|
||||
* aes_encrypt_deinit - Deinitialize AES encryption
|
||||
* @ctx: Context pointer from aes_encrypt_init()
|
||||
*/
|
||||
void wpa_aes_encrypt_deinit(void *ctx);
|
||||
|
||||
/**
|
||||
* aes_decrypt_init - 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
|
||||
*/
|
||||
void * wpa_aes_decrypt_init(const u8 *key, size_t len);
|
||||
|
||||
/**
|
||||
* aes_decrypt - Decrypt one AES block
|
||||
* @ctx: Context pointer from aes_encrypt_init()
|
||||
* @crypt: Encrypted data (16 bytes)
|
||||
* @plain: Buffer for the decrypted data (16 bytes)
|
||||
*/
|
||||
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
|
||||
|
||||
/**
|
||||
* aes_decrypt_deinit - Deinitialize AES decryption
|
||||
* @ctx: Context pointer from aes_encrypt_init()
|
||||
*/
|
||||
void wpa_aes_decrypt_deinit(void *ctx);
|
||||
|
||||
|
||||
enum crypto_hash_alg {
|
||||
CRYPTO_HASH_ALG_MD5, CRYPTO_HASH_ALG_SHA1,
|
||||
CRYPTO_HASH_ALG_HMAC_MD5, CRYPTO_HASH_ALG_HMAC_SHA1,
|
||||
CRYPTO_HASH_ALG_SHA256, CRYPTO_HASH_ALG_HMAC_SHA256
|
||||
};
|
||||
|
||||
struct crypto_hash;
|
||||
|
||||
/**
|
||||
* crypto_hash_init - Initialize hash/HMAC function
|
||||
* @alg: Hash algorithm
|
||||
* @key: Key for keyed hash (e.g., HMAC) or %NULL if not needed
|
||||
* @key_len: Length of the key in bytes
|
||||
* Returns: Pointer to hash context to use with other hash functions or %NULL
|
||||
* on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
|
||||
size_t key_len);
|
||||
|
||||
/**
|
||||
* crypto_hash_update - Add data to hash calculation
|
||||
* @ctx: Context pointer from crypto_hash_init()
|
||||
* @data: Data buffer to add
|
||||
* @len: Length of the buffer
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_hash_finish - Complete hash calculation
|
||||
* @ctx: Context pointer from crypto_hash_init()
|
||||
* @hash: Buffer for hash value or %NULL if caller is just freeing the hash
|
||||
* context
|
||||
* @len: Pointer to length of the buffer or %NULL if caller is just freeing the
|
||||
* hash context; on return, this is set to the actual length of the hash value
|
||||
* Returns: 0 on success, -1 if buffer is too small (len set to needed length),
|
||||
* or -2 on other failures (including failed crypto_hash_update() operations)
|
||||
*
|
||||
* This function calculates the hash value and frees the context buffer that
|
||||
* was used for hash calculation.
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len);
|
||||
|
||||
|
||||
enum crypto_cipher_alg {
|
||||
CRYPTO_CIPHER_NULL = 0, CRYPTO_CIPHER_ALG_AES, CRYPTO_CIPHER_ALG_3DES,
|
||||
CRYPTO_CIPHER_ALG_DES, CRYPTO_CIPHER_ALG_RC2, CRYPTO_CIPHER_ALG_RC4
|
||||
};
|
||||
|
||||
struct crypto_cipher;
|
||||
|
||||
/**
|
||||
* crypto_cipher_init - Initialize block/stream cipher function
|
||||
* @alg: Cipher algorithm
|
||||
* @iv: Initialization vector for block ciphers or %NULL for stream ciphers
|
||||
* @key: Cipher key
|
||||
* @key_len: Length of key in bytes
|
||||
* Returns: Pointer to cipher context to use with other cipher functions or
|
||||
* %NULL on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
|
||||
const u8 *iv, const u8 *key,
|
||||
size_t key_len);
|
||||
|
||||
/**
|
||||
* crypto_cipher_encrypt - Cipher encrypt
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
* @plain: Plaintext to cipher
|
||||
* @crypt: Resulting ciphertext
|
||||
* @len: Length of the plaintext
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
|
||||
const u8 *plain, u8 *crypt, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_cipher_decrypt - Cipher decrypt
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
* @crypt: Ciphertext to decrypt
|
||||
* @plain: Resulting plaintext
|
||||
* @len: Length of the cipher text
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
|
||||
const u8 *crypt, u8 *plain, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_cipher_decrypt - Free cipher context
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void crypto_cipher_deinit(struct crypto_cipher *ctx);
|
||||
|
||||
|
||||
struct crypto_public_key;
|
||||
struct crypto_private_key;
|
||||
|
||||
/**
|
||||
* crypto_public_key_import - Import an RSA public key
|
||||
* @key: Key buffer (DER encoded RSA public key)
|
||||
* @len: Key buffer length in bytes
|
||||
* Returns: Pointer to the public key or %NULL on failure
|
||||
*
|
||||
* This function can just return %NULL if the crypto library supports X.509
|
||||
* parsing. In that case, crypto_public_key_from_cert() is used to import the
|
||||
* public key from a certificate.
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_private_key_import - Import an RSA private key
|
||||
* @key: Key buffer (DER encoded RSA private key)
|
||||
* @len: Key buffer length in bytes
|
||||
* @passwd: Key encryption password or %NULL if key is not encrypted
|
||||
* Returns: Pointer to the private key or %NULL on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_private_key * crypto_private_key_import(const u8 *key,
|
||||
size_t len,
|
||||
const char *passwd);
|
||||
|
||||
/**
|
||||
* crypto_public_key_from_cert - Import an RSA public key from a certificate
|
||||
* @buf: DER encoded X.509 certificate
|
||||
* @len: Certificate buffer length in bytes
|
||||
* Returns: Pointer to public key or %NULL on failure
|
||||
*
|
||||
* This function can just return %NULL if the crypto library does not support
|
||||
* X.509 parsing. In that case, internal code will be used to parse the
|
||||
* certificate and public key is imported using crypto_public_key_import().
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* crypto_public_key_encrypt_pkcs1_v15 - Public key encryption (PKCS #1 v1.5)
|
||||
* @key: Public key
|
||||
* @in: Plaintext buffer
|
||||
* @inlen: Length of plaintext buffer in bytes
|
||||
* @out: Output buffer for encrypted data
|
||||
* @outlen: Length of output buffer in bytes; set to used length on success
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_public_key_encrypt_pkcs1_v15(
|
||||
struct crypto_public_key *key, const u8 *in, size_t inlen,
|
||||
u8 *out, size_t *outlen);
|
||||
|
||||
/**
|
||||
* crypto_private_key_decrypt_pkcs1_v15 - Private key decryption (PKCS #1 v1.5)
|
||||
* @key: Private key
|
||||
* @in: Encrypted buffer
|
||||
* @inlen: Length of encrypted buffer in bytes
|
||||
* @out: Output buffer for encrypted data
|
||||
* @outlen: Length of output buffer in bytes; set to used length on success
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_private_key_decrypt_pkcs1_v15(
|
||||
struct crypto_private_key *key, const u8 *in, size_t inlen,
|
||||
u8 *out, size_t *outlen);
|
||||
|
||||
/**
|
||||
* crypto_private_key_sign_pkcs1 - Sign with private key (PKCS #1)
|
||||
* @key: Private key from crypto_private_key_import()
|
||||
* @in: Plaintext buffer
|
||||
* @inlen: Length of plaintext buffer in bytes
|
||||
* @out: Output buffer for encrypted (signed) data
|
||||
* @outlen: Length of output buffer in bytes; set to used length on success
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
|
||||
const u8 *in, size_t inlen,
|
||||
u8 *out, size_t *outlen);
|
||||
|
||||
/**
|
||||
* crypto_public_key_free - Free public key
|
||||
* @key: Public key
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void crypto_public_key_free(struct crypto_public_key *key);
|
||||
|
||||
/**
|
||||
* crypto_private_key_free - Free private key
|
||||
* @key: Private key from crypto_private_key_import()
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void crypto_private_key_free(struct crypto_private_key *key);
|
||||
|
||||
/**
|
||||
* crypto_public_key_decrypt_pkcs1 - Decrypt PKCS #1 signature
|
||||
* @key: Public key
|
||||
* @crypt: Encrypted signature data (using the private key)
|
||||
* @crypt_len: Encrypted signature data length
|
||||
* @plain: Buffer for plaintext (at least crypt_len bytes)
|
||||
* @plain_len: Plaintext length (max buffer size on input, real len on output);
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int __must_check crypto_public_key_decrypt_pkcs1(
|
||||
struct crypto_public_key *key, const u8 *crypt, size_t crypt_len,
|
||||
u8 *plain, size_t *plain_len);
|
||||
|
||||
/**
|
||||
* crypto_global_init - Initialize crypto wrapper
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_global_init(void);
|
||||
|
||||
/**
|
||||
* crypto_global_deinit - Deinitialize crypto wrapper
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void crypto_global_deinit(void);
|
||||
|
||||
/**
|
||||
* crypto_mod_exp - Modular exponentiation of large integers
|
||||
* @base: Base integer (big endian byte array)
|
||||
* @base_len: Length of base integer in bytes
|
||||
* @power: Power integer (big endian byte array)
|
||||
* @power_len: Length of power integer in bytes
|
||||
* @modulus: Modulus integer (big endian byte array)
|
||||
* @modulus_len: Length of modulus integer in bytes
|
||||
* @result: Buffer for the result
|
||||
* @result_len: Result length (max buffer size on input, real len on output)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function calculates result = base ^ power mod modulus. modules_len is
|
||||
* used as the maximum size of modulus buffer. It is set to the used size on
|
||||
* success.
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
|
||||
const u8 *power, size_t power_len,
|
||||
const u8 *modulus, size_t modulus_len,
|
||||
u8 *result, size_t *result_len);
|
||||
|
||||
/**
|
||||
* rc4_skip - 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.
|
||||
*/
|
||||
int wpa_rc4_skip(const u8 *key, size_t keylen, size_t skip,
|
||||
u8 *data, size_t data_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_H */
|
31
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/dh_group5.h
vendored
Normal file
31
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/dh_group5.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Diffie-Hellman group 5 operations
|
||||
* Copyright (c) 2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef DH_GROUP5_H
|
||||
#define DH_GROUP5_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void * wpa_dh5_init(struct wpabuf **priv, struct wpabuf **publ);
|
||||
struct wpabuf * wpa_dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
|
||||
const struct wpabuf *own_private);
|
||||
void wpa_dh5_free(void *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DH_GROUP5_H */
|
40
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/dh_groups.h
vendored
Normal file
40
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/dh_groups.h
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Diffie-Hellman groups
|
||||
* Copyright (c) 2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef DH_GROUPS_H
|
||||
#define DH_GROUPS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dh_group {
|
||||
int id;
|
||||
const u8 *generator;
|
||||
size_t generator_len;
|
||||
const u8 *prime;
|
||||
size_t prime_len;
|
||||
};
|
||||
|
||||
const struct dh_group * wpa_dh_groups_get(int id);
|
||||
struct wpabuf * wpa_dh_init(const struct dh_group *dh, struct wpabuf **priv);
|
||||
struct wpabuf * wpa_dh_derive_shared(const struct wpabuf *peer_public,
|
||||
const struct wpabuf *own_private,
|
||||
const struct dh_group *dh);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DH_GROUPS_H */
|
73
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/includes.h
vendored
Normal file
73
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/includes.h
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* wpa_supplicant/hostapd - Default include files
|
||||
* Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*
|
||||
* This header file is included into all C files so that commonly used header
|
||||
* files can be selected with OS specific ifdef blocks in one place instead of
|
||||
* having to have OS/C library specific selection in many files.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDES_H
|
||||
#define INCLUDES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Include possible build time configuration before including anything else */
|
||||
//#include "build_config.h" //don't need anymore
|
||||
#ifndef __ets__
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#ifndef _WIN32_WCE
|
||||
#ifndef CONFIG_TI_COMPILER
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#endif /* CONFIG_TI_COMPILER */
|
||||
#include <errno.h>
|
||||
#endif /* _WIN32_WCE */
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef CONFIG_TI_COMPILER
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif /* _MSC_VER */
|
||||
#endif /* CONFIG_TI_COMPILER */
|
||||
|
||||
#ifndef CONFIG_NATIVE_WINDOWS
|
||||
#ifndef CONFIG_TI_COMPILER
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
#ifndef __vxworks
|
||||
#ifndef __SYMBIAN32__
|
||||
//#include <sys/uio.h>
|
||||
#endif /* __SYMBIAN32__ */
|
||||
#include <sys/time.h>
|
||||
#endif /* __vxworks */
|
||||
#endif /* CONFIG_TI_COMPILER */
|
||||
#endif /* CONFIG_NATIVE_WINDOWS */
|
||||
|
||||
#else
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#endif /* !__ets__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDES_H */
|
43
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/md5.h
vendored
Normal file
43
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/md5.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* MD5 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MD5_MAC_LEN 16
|
||||
|
||||
int wpa_hmac_md5_vector(const uint8_t *key, size_t key_len, size_t num_elem,
|
||||
const uint8_t *addr[], const size_t *len, uint8_t *mac);
|
||||
int wpa_hmac_md5(const uint8_t *key, size_t key_len, const uint8_t *data, size_t data_len,
|
||||
uint8_t *mac);
|
||||
#ifdef CONFIG_FIPS
|
||||
int wpa_hmac_md5_vector_non_fips_allow(const uint8_t *key, size_t key_len,
|
||||
size_t num_elem, const uint8_t *addr[],
|
||||
const size_t *len, uint8_t *mac);
|
||||
int wpa_hmac_md5_non_fips_allow(const uint8_t *key, size_t key_len, const uint8_t *data,
|
||||
size_t data_len, uint8_t *mac);
|
||||
#else /* CONFIG_FIPS */
|
||||
#define wpa_hmac_md5_vector_non_fips_allow wpa_hmac_md5_vector
|
||||
#define wpa_hmac_md5_non_fips_allow wpa_hmac_md5
|
||||
#endif /* CONFIG_FIPS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MD5_H */
|
37
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/md5_i.h
vendored
Normal file
37
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/md5_i.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* MD5 internal definitions
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef MD5_I_H
|
||||
#define MD5_I_H
|
||||
|
||||
struct MD5Context {
|
||||
u32 buf[4];
|
||||
u32 bits[2];
|
||||
u8 in[64];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wpa_MD5Init(struct MD5Context *context);
|
||||
void wpa_MD5Update(struct MD5Context *context, unsigned char const *buf,
|
||||
unsigned len);
|
||||
void wpa_MD5Final(unsigned char digest[16], struct MD5Context *context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MD5_I_H */
|
42
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/random.h
vendored
Normal file
42
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/random.h
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Random number generator
|
||||
* Copyright (c) 2010-2011, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef RANDOM_H
|
||||
#define RANDOM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CONFIG_NO_RANDOM_POOL
|
||||
|
||||
#ifdef CONFIG_NO_RANDOM_POOL
|
||||
#define random_init(e) do { } while (0)
|
||||
#define random_deinit() do { } while (0)
|
||||
#define random_add_randomness(b, l) do { } while (0)
|
||||
#define random_get_bytes(b, l) os_get_random((b), (l))
|
||||
#define random_pool_ready() 1
|
||||
#define random_mark_pool_ready() do { } while (0)
|
||||
#else /* CONFIG_NO_RANDOM_POOL */
|
||||
void random_init(const char *entropy_file);
|
||||
void random_deinit(void);
|
||||
void random_add_randomness(const void *buf, size_t len);
|
||||
int random_get_bytes(void *buf, size_t len);
|
||||
#endif /* CONFIG_NO_RANDOM_POOL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RANDOM_H */
|
39
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/sha1.h
vendored
Normal file
39
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/sha1.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* SHA1 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef SHA1_H
|
||||
#define SHA1_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SHA1_MAC_LEN 20
|
||||
|
||||
int wpa_hmac_sha1_vector(const uint8_t *key, size_t key_len, size_t num_elem,
|
||||
const uint8_t *addr[], const size_t *len, uint8_t *mac);
|
||||
int wpa_hmac_sha1(const uint8_t *key, size_t key_len, const uint8_t *data, size_t data_len,
|
||||
uint8_t *mac);
|
||||
int wpa_sha1_prf(const uint8_t *key, size_t key_len, const char *label,
|
||||
const uint8_t *data, size_t data_len, uint8_t *buf, size_t buf_len);
|
||||
int wpa_sha1_t_prf(const uint8_t *key, size_t key_len, const char *label,
|
||||
const uint8_t *seed, size_t seed_len, uint8_t *buf, size_t buf_len);
|
||||
int wpa_pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
|
||||
int iterations, uint8_t *buf, size_t buflen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SHA1_H */
|
37
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/sha1_i.h
vendored
Normal file
37
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/sha1_i.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* SHA1 internal definitions
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef SHA1_I_H
|
||||
#define SHA1_I_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SHA1Context {
|
||||
u32 state[5];
|
||||
u32 count[2];
|
||||
unsigned char buffer[64];
|
||||
};
|
||||
|
||||
void wpa_SHA1Init(struct SHA1Context *context);
|
||||
void wpa_SHA1Update(struct SHA1Context *context, const void *data, u32 len);
|
||||
void wpa_SHA1Final(unsigned char digest[20], struct SHA1Context *context);
|
||||
void wpa_SHA1Transform(u32 state[5], const unsigned char buffer[64]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SHA1_I_H */
|
35
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/sha256.h
vendored
Normal file
35
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/sha256.h
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* SHA256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef SHA256_H
|
||||
#define SHA256_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SHA256_MAC_LEN 32
|
||||
|
||||
void wpa_hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac);
|
||||
void wpa_hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
|
||||
size_t data_len, u8 *mac);
|
||||
void wpa_sha256_prf(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SHA256_H */
|
45
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/wepkey.h
vendored
Normal file
45
cpu/esp8266/vendor/esp-idf/wpa_supplicant/include/crypto/wepkey.h
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* wepkey.h - Generate WEP keys from a passphrase
|
||||
*
|
||||
* Copyright (C) 2008 by OpenMoko, Inc.
|
||||
* Written by Werner Almesberger <werner@openmoko.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* wpkey_64 and wepkey_128 implement the keyphrase hash algorithm found in many
|
||||
* (but not all) common access points, including the Linksys WRT54G series.
|
||||
*/
|
||||
|
||||
#ifndef WEPKEY_H
|
||||
#define WEPKEY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "c_types.h"
|
||||
|
||||
|
||||
#define WEPKEY_64_BYTES 5
|
||||
#define WEPKEY_128_BYTES 13
|
||||
|
||||
|
||||
/*
|
||||
* "size" is the size of the buffer at "out", in bytes. It has to be at least 5
|
||||
* or 13 bytes, respectively. "n" is the key index, in the range 0...3.
|
||||
*/
|
||||
|
||||
size_t wepkey_64(uint8_t *out, size_t size, const char *in, int n);
|
||||
size_t wepkey_128(uint8_t *out, size_t size, const char *in, int n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !WEPKEY_H */
|
19
cpu/esp8266/vendor/esp-idf/wpa_supplicant/port/Makefile
vendored
Normal file
19
cpu/esp8266/vendor/esp-idf/wpa_supplicant/port/Makefile
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
MODULE=esp_idf_wpa_supplicant_port
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
# we have to do it in that way to avoid that $(RIOTBASE)/sys/include/crypto
|
||||
# is found first
|
||||
INCLUDES = -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/wpa_supplicant/port/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/wpa_supplicant/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/wpa_supplicant/port/include
|
||||
CFLAGS += -D__ets__ -DESPRESSIF_USE -DESP_PLATFORM=1
|
||||
CFLAGS += -Wno-strict-aliasing
|
||||
|
||||
include $(RIOTCPU)/$(CPU)/Makefile.include
|
||||
|
||||
INCLUDES += -I$(RIOTBASE)/core/include
|
||||
INCLUDES += -I$(RIOTBASE)/sys/include
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/log/include
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
|
||||
INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include
|
297
cpu/esp8266/vendor/esp-idf/wpa_supplicant/port/include/os.h
vendored
Normal file
297
cpu/esp8266/vendor/esp-idf/wpa_supplicant/port/include/os.h
vendored
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
* OS specific functions
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef OS_H
|
||||
#define OS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
#include "syscalls.h"
|
||||
#define os_memset system_secure_memset
|
||||
#endif
|
||||
|
||||
#include "esp_types.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "esp_err.h"
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "esp_libc.h"
|
||||
|
||||
typedef long os_time_t;
|
||||
|
||||
/**
|
||||
* os_sleep - Sleep (sec, usec)
|
||||
* @sec: Number of seconds to sleep
|
||||
* @usec: Number of microseconds to sleep
|
||||
*/
|
||||
void os_sleep(os_time_t sec, os_time_t usec);
|
||||
|
||||
struct os_time {
|
||||
os_time_t sec;
|
||||
os_time_t usec;
|
||||
};
|
||||
|
||||
/**
|
||||
* os_get_time - Get current time (sec, usec)
|
||||
* @t: Pointer to buffer for the time
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_get_time(struct os_time *t);
|
||||
|
||||
|
||||
/* Helper macros for handling struct os_time */
|
||||
|
||||
#define os_time_before(a, b) \
|
||||
((a)->sec < (b)->sec || \
|
||||
((a)->sec == (b)->sec && (a)->usec < (b)->usec))
|
||||
|
||||
#define os_time_sub(a, b, res) do { \
|
||||
(res)->sec = (a)->sec - (b)->sec; \
|
||||
(res)->usec = (a)->usec - (b)->usec; \
|
||||
if ((res)->usec < 0) { \
|
||||
(res)->sec--; \
|
||||
(res)->usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* os_mktime - Convert broken-down time into seconds since 1970-01-01
|
||||
* @year: Four digit year
|
||||
* @month: Month (1 .. 12)
|
||||
* @day: Day of month (1 .. 31)
|
||||
* @hour: Hour (0 .. 23)
|
||||
* @min: Minute (0 .. 59)
|
||||
* @sec: Second (0 .. 60)
|
||||
* @t: Buffer for returning calendar time representation (seconds since
|
||||
* 1970-01-01 00:00:00)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* Note: The result is in seconds from Epoch, i.e., in UTC, not in local time
|
||||
* which is used by POSIX mktime().
|
||||
*/
|
||||
int os_mktime(int year, int month, int day, int hour, int min, int sec,
|
||||
os_time_t *t);
|
||||
|
||||
|
||||
/**
|
||||
* os_daemonize - Run in the background (detach from the controlling terminal)
|
||||
* @pid_file: File name to write the process ID to or %NULL to skip this
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_daemonize(const char *pid_file);
|
||||
|
||||
/**
|
||||
* os_daemonize_terminate - Stop running in the background (remove pid file)
|
||||
* @pid_file: File name to write the process ID to or %NULL to skip this
|
||||
*/
|
||||
void os_daemonize_terminate(const char *pid_file);
|
||||
|
||||
/**
|
||||
* os_get_random - Get cryptographically strong pseudo random data
|
||||
* @buf: Buffer for pseudo random data
|
||||
* @len: Length of the buffer
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_get_random(unsigned char *buf, size_t len);
|
||||
|
||||
/**
|
||||
* os_random - Get pseudo random value (not necessarily very strong)
|
||||
* Returns: Pseudo random value
|
||||
*/
|
||||
unsigned long os_random(void);
|
||||
|
||||
/**
|
||||
* os_rel2abs_path - Get an absolute path for a file
|
||||
* @rel_path: Relative path to a file
|
||||
* Returns: Absolute path for the file or %NULL on failure
|
||||
*
|
||||
* This function tries to convert a relative path of a file to an absolute path
|
||||
* in order for the file to be found even if current working directory has
|
||||
* changed. The returned value is allocated and caller is responsible for
|
||||
* freeing it. It is acceptable to just return the same path in an allocated
|
||||
* buffer, e.g., return strdup(rel_path). This function is only used to find
|
||||
* configuration files when os_daemonize() may have changed the current working
|
||||
* directory and relative path would be pointing to a different location.
|
||||
*/
|
||||
char * os_rel2abs_path(const char *rel_path);
|
||||
|
||||
/**
|
||||
* os_program_init - Program initialization (called at start)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is called when a programs starts. If there are any OS specific
|
||||
* processing that is needed, it can be placed here. It is also acceptable to
|
||||
* just return 0 if not special processing is needed.
|
||||
*/
|
||||
int os_program_init(void);
|
||||
|
||||
/**
|
||||
* os_program_deinit - Program deinitialization (called just before exit)
|
||||
*
|
||||
* This function is called just before a program exists. If there are any OS
|
||||
* specific processing, e.g., freeing resourced allocated in os_program_init(),
|
||||
* it should be done here. It is also acceptable for this function to do
|
||||
* nothing.
|
||||
*/
|
||||
void os_program_deinit(void);
|
||||
|
||||
/**
|
||||
* os_setenv - Set environment variable
|
||||
* @name: Name of the variable
|
||||
* @value: Value to set to the variable
|
||||
* @overwrite: Whether existing variable should be overwritten
|
||||
* Returns: 0 on success, -1 on error
|
||||
*
|
||||
* This function is only used for wpa_cli action scripts. OS wrapper does not
|
||||
* need to implement this if such functionality is not needed.
|
||||
*/
|
||||
int os_setenv(const char *name, const char *value, int overwrite);
|
||||
|
||||
/**
|
||||
* os_unsetenv - Delete environent variable
|
||||
* @name: Name of the variable
|
||||
* Returns: 0 on success, -1 on error
|
||||
*
|
||||
* This function is only used for wpa_cli action scripts. OS wrapper does not
|
||||
* need to implement this if such functionality is not needed.
|
||||
*/
|
||||
int os_unsetenv(const char *name);
|
||||
|
||||
/**
|
||||
* os_readfile - Read a file to an allocated memory buffer
|
||||
* @name: Name of the file to read
|
||||
* @len: For returning the length of the allocated buffer
|
||||
* Returns: Pointer to the allocated buffer or %NULL on failure
|
||||
*
|
||||
* This function allocates memory and reads the given file to this buffer. Both
|
||||
* binary and text files can be read with this function. The caller is
|
||||
* responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
char * os_readfile(const char *name, size_t *len);
|
||||
|
||||
/*
|
||||
* The following functions are wrapper for standard ANSI C or POSIX functions.
|
||||
* By default, they are just defined to use the standard function name and no
|
||||
* os_*.c implementation is needed for them. This avoids extra function calls
|
||||
* by allowing the C pre-processor take care of the function name mapping.
|
||||
*
|
||||
* If the target system uses a C library that does not provide these functions,
|
||||
* build_config.h can be used to define the wrappers to use a different
|
||||
* function name. This can be done on function-by-function basis since the
|
||||
* defines here are only used if build_config.h does not define the os_* name.
|
||||
* If needed, os_*.c file can be used to implement the functions that are not
|
||||
* included in the C library on the target system. Alternatively,
|
||||
* OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
|
||||
* these functions need to be implemented in os_*.c file for the target system.
|
||||
*/
|
||||
|
||||
#ifndef os_bzero
|
||||
#define os_bzero(s, n) bzero(s, n)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef os_strdup
|
||||
#ifdef _MSC_VER
|
||||
#define os_strdup(s) _strdup(s)
|
||||
#else
|
||||
#define os_strdup(s) strdup(s)
|
||||
#endif
|
||||
#endif
|
||||
char * ets_strdup(const char *s);
|
||||
|
||||
#ifndef os_memcpy
|
||||
#define os_memcpy(d, s, n) memcpy((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_memmove
|
||||
#define os_memmove(d, s, n) memmove((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_memset
|
||||
#define os_memset(s, c, n) memset(s, c, n)
|
||||
#endif
|
||||
#ifndef os_memcmp
|
||||
#define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
|
||||
#endif
|
||||
|
||||
#ifndef os_strlen
|
||||
#define os_strlen(s) strlen(s)
|
||||
#endif
|
||||
#ifndef os_strcasecmp
|
||||
#ifdef _MSC_VER
|
||||
#define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
|
||||
#else
|
||||
#define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef os_strncasecmp
|
||||
#ifdef _MSC_VER
|
||||
#define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
|
||||
#else
|
||||
#define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef os_strchr
|
||||
#define os_strchr(s, c) strchr((s), (c))
|
||||
#endif
|
||||
#ifndef os_strcmp
|
||||
#define os_strcmp(s1, s2) strcmp((s1), (s2))
|
||||
#endif
|
||||
#ifndef os_strncmp
|
||||
#define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
|
||||
#endif
|
||||
#ifndef os_strncpy
|
||||
#define os_strncpy(d, s, n) strncpy((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_strrchr
|
||||
//hard cold
|
||||
#define os_strrchr(s, c) NULL
|
||||
#endif
|
||||
#ifndef os_strstr
|
||||
#define os_strstr(h, n) strstr((h), (n))
|
||||
#endif
|
||||
|
||||
#ifndef os_snprintf
|
||||
#ifdef _MSC_VER
|
||||
#define os_snprintf _snprintf
|
||||
#else
|
||||
#define os_snprintf vsnprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* os_strlcpy - Copy a string with size bound and NUL-termination
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @siz: Size of the target buffer
|
||||
* Returns: Total length of the target string (length of src) (not including
|
||||
* NUL-termination)
|
||||
*
|
||||
* This function matches in behavior with the strlcpy(3) function in OpenBSD.
|
||||
*/
|
||||
size_t os_strlcpy(char *dest, const char *src, size_t siz);
|
||||
|
||||
void *_xmalloc(size_t n);
|
||||
void _xfree(void *ptr);
|
||||
void *_xrealloc(void *ptr, size_t n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OS_H */
|
67
cpu/esp8266/vendor/esp-idf/wpa_supplicant/port/os_xtensa.c
vendored
Normal file
67
cpu/esp8266/vendor/esp-idf/wpa_supplicant/port/os_xtensa.c
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* wpa_supplicant/hostapd / Internal implementation of OS specific functions
|
||||
* Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*
|
||||
* This file is an example of operating system specific wrapper functions.
|
||||
* This version implements many of the functions internally, so it can be used
|
||||
* to fill in missing functions from the target system C libraries.
|
||||
*
|
||||
* Some of the functions are using standard C library calls in order to keep
|
||||
* this file in working condition to allow the functions to be tested on a
|
||||
* Linux target. Please note that OS_NO_C_LIB_DEFINES needs to be defined for
|
||||
* this file to work correctly. Note that these implementations are only
|
||||
* examples and are not optimized for speed.
|
||||
*/
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "os.h"
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "esp_system.h"
|
||||
|
||||
#ifndef RIOT_VERSION
|
||||
|
||||
int os_get_time(struct os_time *t)
|
||||
{
|
||||
return gettimeofday((struct timeval*) t, NULL);
|
||||
}
|
||||
|
||||
unsigned long os_random(void)
|
||||
{
|
||||
return esp_random();
|
||||
}
|
||||
|
||||
unsigned long r_rand(void) __attribute__((alias("os_random")));
|
||||
|
||||
|
||||
int os_get_random(unsigned char *buf, size_t len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
unsigned long tmp;
|
||||
|
||||
for (i = 0; i < ((len + 3) & ~3) / 4; i++) {
|
||||
tmp = r_rand();
|
||||
|
||||
for (j = 0; j < 4; j++) {
|
||||
if ((i * 4 + j) < len) {
|
||||
buf[i * 4 + j] = (uint8_t)(tmp >> (j * 8));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
21
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/Makefile
vendored
Normal file
21
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/Makefile
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MODULE=esp_idf_wpa_supplicant_crypto
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
# we have to do it in that way to avoid that $(RIOTBASE)/sys/include/crypto
|
||||
# is found first
|
||||
INCLUDES = -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/wpa_supplicant/include
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/wpa_supplicant/port/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/wpa_supplicant/include
|
||||
INCLUDES += -I$(ESP8266_SDK_DIR)/components/wpa_supplicant/port/include
|
||||
CFLAGS += -D__ets__ -DESPRESSIF_USE -DESP_PLATFORM=1
|
||||
CFLAGS += -Wno-strict-aliasing
|
||||
|
||||
include $(RIOTCPU)/$(CPU)/Makefile.include
|
||||
|
||||
INCLUDES += -I$(RIOTBASE)/core/include
|
||||
INCLUDES += -I$(RIOTBASE)/sys/include
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/log/include
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
|
||||
INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include
|
||||
|
88
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-cbc.c
vendored
Normal file
88
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-cbc.c
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* AES-128 CBC
|
||||
*
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/aes.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
|
||||
/**
|
||||
* aes_128_cbc_encrypt - AES-128 CBC encryption
|
||||
* @key: Encryption key
|
||||
* @iv: Encryption IV for CBC mode (16 bytes)
|
||||
* @data: Data to encrypt in-place
|
||||
* @data_len: Length of data in bytes (must be divisible by 16)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
wpa_aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
|
||||
{
|
||||
void *ctx;
|
||||
u8 cbc[AES_BLOCK_SIZE];
|
||||
u8 *pos = data;
|
||||
int i, j, blocks;
|
||||
|
||||
ctx = wpa_aes_encrypt_init(key, 16);
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
|
||||
|
||||
blocks = data_len / AES_BLOCK_SIZE;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
for (j = 0; j < AES_BLOCK_SIZE; j++)
|
||||
cbc[j] ^= pos[j];
|
||||
wpa_aes_encrypt(ctx, cbc, cbc);
|
||||
os_memcpy(pos, cbc, AES_BLOCK_SIZE);
|
||||
pos += AES_BLOCK_SIZE;
|
||||
}
|
||||
wpa_aes_encrypt_deinit(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* aes_128_cbc_decrypt - AES-128 CBC decryption
|
||||
* @key: Decryption key
|
||||
* @iv: Decryption IV for CBC mode (16 bytes)
|
||||
* @data: Data to decrypt in-place
|
||||
* @data_len: Length of data in bytes (must be divisible by 16)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
wpa_aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
|
||||
{
|
||||
void *ctx;
|
||||
u8 cbc[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE];
|
||||
u8 *pos = data;
|
||||
int i, j, blocks;
|
||||
|
||||
ctx = wpa_aes_decrypt_init(key, 16);
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
|
||||
|
||||
blocks = data_len / AES_BLOCK_SIZE;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
os_memcpy(tmp, pos, AES_BLOCK_SIZE);
|
||||
wpa_aes_decrypt(ctx, pos, pos);
|
||||
for (j = 0; j < AES_BLOCK_SIZE; j++)
|
||||
pos[j] ^= cbc[j];
|
||||
os_memcpy(cbc, tmp, AES_BLOCK_SIZE);
|
||||
pos += AES_BLOCK_SIZE;
|
||||
}
|
||||
wpa_aes_decrypt_deinit(ctx);
|
||||
return 0;
|
||||
}
|
172
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-internal-dec.c
vendored
Normal file
172
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-internal-dec.c
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher - decrypt
|
||||
*
|
||||
* Modifications to public domain implementation:
|
||||
* - support only 128-bit keys
|
||||
* - cleanup
|
||||
* - use C pre-processor to make it easier to change S table access
|
||||
* - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
|
||||
* cost of reduced throughput (quite small difference on Pentium 4,
|
||||
* 10-25% when using -O1 or -O2 optimization)
|
||||
*
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/aes_i.h"
|
||||
|
||||
|
||||
|
||||
//static unsigned char aes_priv_buf[AES_PRIV_SIZE];
|
||||
|
||||
/**
|
||||
* Expand the cipher key into the decryption key schedule.
|
||||
*
|
||||
* @return the number of rounds for the given cipher key size.
|
||||
*/
|
||||
static int wpa_rijndaelKeySetupDec(u32 rk[], const u8 cipherKey[], int keyBits)
|
||||
{
|
||||
int Nr, i, j;
|
||||
u32 temp;
|
||||
|
||||
/* expand the cipher key: */
|
||||
Nr = wpa_rijndaelKeySetupEnc(rk, cipherKey, keyBits);
|
||||
if (Nr < 0)
|
||||
return Nr;
|
||||
/* invert the order of the round keys: */
|
||||
for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) {
|
||||
temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
|
||||
temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
|
||||
temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
|
||||
temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
|
||||
}
|
||||
/* apply the inverse MixColumn transform to all round keys but the
|
||||
* first and the last: */
|
||||
for (i = 1; i < Nr; i++) {
|
||||
rk += 4;
|
||||
for (j = 0; j < 4; j++) {
|
||||
rk[j] = TD0_(TE4((rk[j] >> 24) )) ^
|
||||
TD1_(TE4((rk[j] >> 16) & 0xff)) ^
|
||||
TD2_(TE4((rk[j] >> 8) & 0xff)) ^
|
||||
TD3_(TE4((rk[j] ) & 0xff));
|
||||
}
|
||||
}
|
||||
|
||||
return Nr;
|
||||
}
|
||||
|
||||
void * wpa_aes_decrypt_init(const u8 *key, size_t len)
|
||||
{
|
||||
u32 *rk;
|
||||
int res;
|
||||
rk = os_malloc(AES_PRIV_SIZE);
|
||||
if (rk == NULL)
|
||||
return NULL;
|
||||
res = wpa_rijndaelKeySetupDec(rk, key, len * 8);
|
||||
if (res < 0) {
|
||||
os_free(rk);
|
||||
return NULL;
|
||||
}
|
||||
rk[AES_PRIV_NR_POS] = res;
|
||||
return rk;
|
||||
}
|
||||
|
||||
static void wpa_rijndaelDecrypt(const u32 rk[/*44*/], int Nr, const u8 ct[16],
|
||||
u8 pt[16])
|
||||
{
|
||||
u32 s0, s1, s2, s3, t0, t1, t2, t3;
|
||||
#ifndef FULL_UNROLL
|
||||
int r;
|
||||
#endif /* ?FULL_UNROLL */
|
||||
|
||||
/*
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
s0 = GETU32(ct ) ^ rk[0];
|
||||
s1 = GETU32(ct + 4) ^ rk[1];
|
||||
s2 = GETU32(ct + 8) ^ rk[2];
|
||||
s3 = GETU32(ct + 12) ^ rk[3];
|
||||
|
||||
#define ROUND(i,d,s) \
|
||||
d##0 = TD0(s##0) ^ TD1(s##3) ^ TD2(s##2) ^ TD3(s##1) ^ rk[4 * i]; \
|
||||
d##1 = TD0(s##1) ^ TD1(s##0) ^ TD2(s##3) ^ TD3(s##2) ^ rk[4 * i + 1]; \
|
||||
d##2 = TD0(s##2) ^ TD1(s##1) ^ TD2(s##0) ^ TD3(s##3) ^ rk[4 * i + 2]; \
|
||||
d##3 = TD0(s##3) ^ TD1(s##2) ^ TD2(s##1) ^ TD3(s##0) ^ rk[4 * i + 3]
|
||||
|
||||
#ifdef FULL_UNROLL
|
||||
|
||||
ROUND(1,t,s);
|
||||
ROUND(2,s,t);
|
||||
ROUND(3,t,s);
|
||||
ROUND(4,s,t);
|
||||
ROUND(5,t,s);
|
||||
ROUND(6,s,t);
|
||||
ROUND(7,t,s);
|
||||
ROUND(8,s,t);
|
||||
ROUND(9,t,s);
|
||||
if (Nr > 10) {
|
||||
ROUND(10,s,t);
|
||||
ROUND(11,t,s);
|
||||
if (Nr > 12) {
|
||||
ROUND(12,s,t);
|
||||
ROUND(13,t,s);
|
||||
}
|
||||
}
|
||||
|
||||
rk += Nr << 2;
|
||||
|
||||
#else /* !FULL_UNROLL */
|
||||
|
||||
/* Nr - 1 full rounds: */
|
||||
r = Nr >> 1;
|
||||
for (;;) {
|
||||
ROUND(1,t,s);
|
||||
rk += 8;
|
||||
if (--r == 0)
|
||||
break;
|
||||
ROUND(0,s,t);
|
||||
}
|
||||
|
||||
#endif /* ?FULL_UNROLL */
|
||||
|
||||
#undef ROUND
|
||||
|
||||
/*
|
||||
* apply last round and
|
||||
* map cipher state to byte array block:
|
||||
*/
|
||||
s0 = TD41(t0) ^ TD42(t3) ^ TD43(t2) ^ TD44(t1) ^ rk[0];
|
||||
PUTU32(pt , s0);
|
||||
s1 = TD41(t1) ^ TD42(t0) ^ TD43(t3) ^ TD44(t2) ^ rk[1];
|
||||
PUTU32(pt + 4, s1);
|
||||
s2 = TD41(t2) ^ TD42(t1) ^ TD43(t0) ^ TD44(t3) ^ rk[2];
|
||||
PUTU32(pt + 8, s2);
|
||||
s3 = TD41(t3) ^ TD42(t2) ^ TD43(t1) ^ TD44(t0) ^ rk[3];
|
||||
PUTU32(pt + 12, s3);
|
||||
}
|
||||
|
||||
void wpa_aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
|
||||
{
|
||||
u32 *rk = ctx;
|
||||
wpa_rijndaelDecrypt(ctx, rk[AES_PRIV_NR_POS], crypt, plain);
|
||||
}
|
||||
|
||||
|
||||
void wpa_aes_decrypt_deinit(void *ctx)
|
||||
{
|
||||
os_memset(ctx, 0, AES_PRIV_SIZE);
|
||||
os_free(ctx);
|
||||
}
|
134
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-internal-enc.c
vendored
Normal file
134
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-internal-enc.c
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher - encrypt
|
||||
*
|
||||
* Modifications to public domain implementation:
|
||||
* - support only 128-bit keys
|
||||
* - cleanup
|
||||
* - use C pre-processor to make it easier to change S table access
|
||||
* - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
|
||||
* cost of reduced throughput (quite small difference on Pentium 4,
|
||||
* 10-25% when using -O1 or -O2 optimization)
|
||||
*
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/aes_i.h"
|
||||
|
||||
#include "os.h"
|
||||
|
||||
void wpa_rijndaelEncrypt(const u32 rk[], int Nr, const u8 pt[16], u8 ct[16])
|
||||
{
|
||||
u32 s0, s1, s2, s3, t0, t1, t2, t3;
|
||||
#ifndef FULL_UNROLL
|
||||
int r;
|
||||
#endif /* ?FULL_UNROLL */
|
||||
|
||||
/*
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
s0 = GETU32(pt ) ^ rk[0];
|
||||
s1 = GETU32(pt + 4) ^ rk[1];
|
||||
s2 = GETU32(pt + 8) ^ rk[2];
|
||||
s3 = GETU32(pt + 12) ^ rk[3];
|
||||
|
||||
#define ROUND(i,d,s) \
|
||||
d##0 = TE0(s##0) ^ TE1(s##1) ^ TE2(s##2) ^ TE3(s##3) ^ rk[4 * i]; \
|
||||
d##1 = TE0(s##1) ^ TE1(s##2) ^ TE2(s##3) ^ TE3(s##0) ^ rk[4 * i + 1]; \
|
||||
d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[4 * i + 2]; \
|
||||
d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[4 * i + 3]
|
||||
|
||||
#ifdef FULL_UNROLL
|
||||
|
||||
ROUND(1,t,s);
|
||||
ROUND(2,s,t);
|
||||
ROUND(3,t,s);
|
||||
ROUND(4,s,t);
|
||||
ROUND(5,t,s);
|
||||
ROUND(6,s,t);
|
||||
ROUND(7,t,s);
|
||||
ROUND(8,s,t);
|
||||
ROUND(9,t,s);
|
||||
if (Nr > 10) {
|
||||
ROUND(10,s,t);
|
||||
ROUND(11,t,s);
|
||||
if (Nr > 12) {
|
||||
ROUND(12,s,t);
|
||||
ROUND(13,t,s);
|
||||
}
|
||||
}
|
||||
|
||||
rk += Nr << 2;
|
||||
|
||||
#else /* !FULL_UNROLL */
|
||||
|
||||
/* Nr - 1 full rounds: */
|
||||
r = Nr >> 1;
|
||||
for (;;) {
|
||||
ROUND(1,t,s);
|
||||
rk += 8;
|
||||
if (--r == 0)
|
||||
break;
|
||||
ROUND(0,s,t);
|
||||
}
|
||||
|
||||
#endif /* ?FULL_UNROLL */
|
||||
|
||||
#undef ROUND
|
||||
|
||||
/*
|
||||
* apply last round and
|
||||
* map cipher state to byte array block:
|
||||
*/
|
||||
s0 = TE41(t0) ^ TE42(t1) ^ TE43(t2) ^ TE44(t3) ^ rk[0];
|
||||
PUTU32(ct , s0);
|
||||
s1 = TE41(t1) ^ TE42(t2) ^ TE43(t3) ^ TE44(t0) ^ rk[1];
|
||||
PUTU32(ct + 4, s1);
|
||||
s2 = TE41(t2) ^ TE42(t3) ^ TE43(t0) ^ TE44(t1) ^ rk[2];
|
||||
PUTU32(ct + 8, s2);
|
||||
s3 = TE41(t3) ^ TE42(t0) ^ TE43(t1) ^ TE44(t2) ^ rk[3];
|
||||
PUTU32(ct + 12, s3);
|
||||
}
|
||||
|
||||
|
||||
void * wpa_aes_encrypt_init(const u8 *key, size_t len)
|
||||
{
|
||||
u32 *rk;
|
||||
int res;
|
||||
rk = os_malloc(AES_PRIV_SIZE);
|
||||
if (rk == NULL)
|
||||
return NULL;
|
||||
res = wpa_rijndaelKeySetupEnc(rk, key, len * 8);
|
||||
if (res < 0) {
|
||||
os_free(rk);
|
||||
return NULL;
|
||||
}
|
||||
rk[AES_PRIV_NR_POS] = res;
|
||||
return rk;
|
||||
}
|
||||
|
||||
|
||||
void wpa_aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
|
||||
{
|
||||
u32 *rk = ctx;
|
||||
wpa_rijndaelEncrypt(ctx, rk[AES_PRIV_NR_POS], plain, crypt);
|
||||
}
|
||||
|
||||
|
||||
void wpa_aes_encrypt_deinit(void *ctx)
|
||||
{
|
||||
os_memset(ctx, 0, AES_PRIV_SIZE);
|
||||
os_free(ctx);
|
||||
}
|
857
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-internal.c
vendored
Normal file
857
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-internal.c
vendored
Normal file
@ -0,0 +1,857 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher
|
||||
*
|
||||
* Modifications to public domain implementation:
|
||||
* - support only 128-bit keys
|
||||
* - cleanup
|
||||
* - use C pre-processor to make it easier to change S table access
|
||||
* - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
|
||||
* cost of reduced throughput (quite small difference on Pentium 4,
|
||||
* 10-25% when using -O1 or -O2 optimization)
|
||||
*
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
#ifdef RIOT_VERSION
|
||||
#pragma weak rijndaelKeySetupEnc
|
||||
#endif
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
//#include "wpa/common.h"
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/aes_i.h"
|
||||
|
||||
/*
|
||||
* rijndael-alg-fst.c
|
||||
*
|
||||
* @version 3.0 (December 2000)
|
||||
*
|
||||
* Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||
*
|
||||
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||
* @author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||
*
|
||||
* This code is hereby placed in the public domain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define AES_SMALL_TABLES
|
||||
|
||||
/*
|
||||
Te0[x] = S [x].[02, 01, 01, 03];
|
||||
Te1[x] = S [x].[03, 02, 01, 01];
|
||||
Te2[x] = S [x].[01, 03, 02, 01];
|
||||
Te3[x] = S [x].[01, 01, 03, 02];
|
||||
Te4[x] = S [x].[01, 01, 01, 01];
|
||||
|
||||
Td0[x] = Si[x].[0e, 09, 0d, 0b];
|
||||
Td1[x] = Si[x].[0b, 0e, 09, 0d];
|
||||
Td2[x] = Si[x].[0d, 0b, 0e, 09];
|
||||
Td3[x] = Si[x].[09, 0d, 0b, 0e];
|
||||
Td4[x] = Si[x].[01, 01, 01, 01];
|
||||
*/
|
||||
|
||||
const u32 Te0[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
|
||||
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
|
||||
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
|
||||
0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
|
||||
0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
|
||||
0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
|
||||
0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
|
||||
0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
|
||||
0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
|
||||
0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
|
||||
0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
|
||||
0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
|
||||
0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
|
||||
0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
|
||||
0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
|
||||
0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
|
||||
0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
|
||||
0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
|
||||
0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
|
||||
0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
|
||||
0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
|
||||
0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
|
||||
0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
|
||||
0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
|
||||
0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
|
||||
0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
|
||||
0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
|
||||
0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
|
||||
0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
|
||||
0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
|
||||
0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
|
||||
0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
|
||||
0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
|
||||
0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
|
||||
0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
|
||||
0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
|
||||
0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
|
||||
0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
|
||||
0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
|
||||
0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
|
||||
0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
|
||||
0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
|
||||
0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
|
||||
0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
|
||||
0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
|
||||
0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
|
||||
0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
|
||||
0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
|
||||
0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
|
||||
0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
|
||||
0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
|
||||
0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
|
||||
0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
|
||||
0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
|
||||
0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
|
||||
0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
|
||||
0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
|
||||
0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
|
||||
0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
|
||||
0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
|
||||
0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
|
||||
0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
|
||||
0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
|
||||
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
|
||||
};
|
||||
#ifndef AES_SMALL_TABLES
|
||||
const u32 Te1[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
|
||||
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
|
||||
0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
|
||||
0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
|
||||
0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
|
||||
0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
|
||||
0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
|
||||
0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
|
||||
0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
|
||||
0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
|
||||
0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
|
||||
0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
|
||||
0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
|
||||
0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
|
||||
0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
|
||||
0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
|
||||
0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
|
||||
0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
|
||||
0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
|
||||
0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
|
||||
0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
|
||||
0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
|
||||
0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
|
||||
0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
|
||||
0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
|
||||
0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
|
||||
0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
|
||||
0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
|
||||
0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
|
||||
0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
|
||||
0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
|
||||
0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
|
||||
0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
|
||||
0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
|
||||
0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
|
||||
0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
|
||||
0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
|
||||
0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
|
||||
0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
|
||||
0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
|
||||
0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
|
||||
0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
|
||||
0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
|
||||
0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
|
||||
0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
|
||||
0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
|
||||
0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
|
||||
0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
|
||||
0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
|
||||
0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
|
||||
0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
|
||||
0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
|
||||
0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
|
||||
0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
|
||||
0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
|
||||
0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
|
||||
0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
|
||||
0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
|
||||
0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
|
||||
0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
|
||||
0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
|
||||
0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
|
||||
0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
|
||||
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
|
||||
};
|
||||
const u32 Te2[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
|
||||
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
|
||||
0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
|
||||
0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
|
||||
0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
|
||||
0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
|
||||
0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
|
||||
0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
|
||||
0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
|
||||
0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
|
||||
0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
|
||||
0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
|
||||
0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
|
||||
0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
|
||||
0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
|
||||
0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
|
||||
0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
|
||||
0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
|
||||
0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
|
||||
0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
|
||||
0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
|
||||
0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
|
||||
0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
|
||||
0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
|
||||
0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
|
||||
0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
|
||||
0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
|
||||
0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
|
||||
0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
|
||||
0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
|
||||
0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
|
||||
0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
|
||||
0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
|
||||
0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
|
||||
0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
|
||||
0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
|
||||
0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
|
||||
0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
|
||||
0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
|
||||
0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
|
||||
0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
|
||||
0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
|
||||
0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
|
||||
0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
|
||||
0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
|
||||
0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
|
||||
0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
|
||||
0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
|
||||
0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
|
||||
0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
|
||||
0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
|
||||
0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
|
||||
0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
|
||||
0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
|
||||
0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
|
||||
0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
|
||||
0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
|
||||
0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
|
||||
0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
|
||||
0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
|
||||
0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
|
||||
0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
|
||||
0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
|
||||
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
|
||||
};
|
||||
const u32 Te3[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
|
||||
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
|
||||
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
|
||||
0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
|
||||
0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
|
||||
0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
|
||||
0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
|
||||
0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
|
||||
0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
|
||||
0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
|
||||
0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
|
||||
0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
|
||||
0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
|
||||
0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
|
||||
0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
|
||||
0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
|
||||
0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
|
||||
0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
|
||||
0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
|
||||
0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
|
||||
0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
|
||||
0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
|
||||
0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
|
||||
0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
|
||||
0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
|
||||
0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
|
||||
0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
|
||||
0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
|
||||
0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
|
||||
0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
|
||||
0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
|
||||
0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
|
||||
0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
|
||||
0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
|
||||
0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
|
||||
0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
|
||||
0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
|
||||
0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
|
||||
0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
|
||||
0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
|
||||
0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
|
||||
0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
|
||||
0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
|
||||
0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
|
||||
0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
|
||||
0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
|
||||
0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
|
||||
0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
|
||||
0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
|
||||
0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
|
||||
0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
|
||||
0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
|
||||
0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
|
||||
0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
|
||||
0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
|
||||
0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
|
||||
0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
|
||||
0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
|
||||
0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
|
||||
0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
|
||||
0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
|
||||
0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
|
||||
0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
|
||||
0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
|
||||
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
|
||||
};
|
||||
const u32 Te4[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
|
||||
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
|
||||
0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
|
||||
0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
|
||||
0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
|
||||
0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
|
||||
0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
|
||||
0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
|
||||
0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
|
||||
0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
|
||||
0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
|
||||
0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
|
||||
0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
|
||||
0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
|
||||
0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
|
||||
0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
|
||||
0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
|
||||
0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
|
||||
0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
|
||||
0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
|
||||
0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
|
||||
0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
|
||||
0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
|
||||
0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
|
||||
0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
|
||||
0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
|
||||
0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
|
||||
0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
|
||||
0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
|
||||
0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
|
||||
0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
|
||||
0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
|
||||
0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
|
||||
0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
|
||||
0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
|
||||
0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
|
||||
0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
|
||||
0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
|
||||
0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
|
||||
0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
|
||||
0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
|
||||
0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
|
||||
0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
|
||||
0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
|
||||
0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
|
||||
0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
|
||||
0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
|
||||
0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
|
||||
0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
|
||||
0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
|
||||
0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
|
||||
0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
|
||||
0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
|
||||
0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
|
||||
0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
|
||||
0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
|
||||
0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
|
||||
0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
|
||||
0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
|
||||
0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
|
||||
0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
|
||||
0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
|
||||
0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
|
||||
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
|
||||
};
|
||||
#endif /* AES_SMALL_TABLES */
|
||||
const u32 Td0[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
|
||||
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
|
||||
0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
|
||||
0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
|
||||
0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
|
||||
0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
|
||||
0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
|
||||
0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
|
||||
0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
|
||||
0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
|
||||
0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
|
||||
0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
|
||||
0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
|
||||
0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
|
||||
0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
|
||||
0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
|
||||
0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
|
||||
0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
|
||||
0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
|
||||
0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
|
||||
0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
|
||||
0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
|
||||
0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
|
||||
0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
|
||||
0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
|
||||
0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
|
||||
0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
|
||||
0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
|
||||
0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
|
||||
0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
|
||||
0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
|
||||
0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
|
||||
0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
|
||||
0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
|
||||
0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
|
||||
0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
|
||||
0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
|
||||
0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
|
||||
0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
|
||||
0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
|
||||
0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
|
||||
0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
|
||||
0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
|
||||
0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
|
||||
0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
|
||||
0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
|
||||
0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
|
||||
0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
|
||||
0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
|
||||
0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
|
||||
0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
|
||||
0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
|
||||
0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
|
||||
0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
|
||||
0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
|
||||
0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
|
||||
0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
|
||||
0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
|
||||
0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
|
||||
0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
|
||||
0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
|
||||
0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
|
||||
0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
|
||||
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
|
||||
};
|
||||
#ifndef AES_SMALL_TABLES
|
||||
const u32 Td1[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
|
||||
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
|
||||
0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
|
||||
0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
|
||||
0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
|
||||
0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
|
||||
0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
|
||||
0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
|
||||
0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
|
||||
0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
|
||||
0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
|
||||
0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
|
||||
0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
|
||||
0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
|
||||
0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
|
||||
0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
|
||||
0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
|
||||
0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
|
||||
0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
|
||||
0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
|
||||
0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
|
||||
0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
|
||||
0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
|
||||
0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
|
||||
0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
|
||||
0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
|
||||
0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
|
||||
0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
|
||||
0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
|
||||
0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
|
||||
0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
|
||||
0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
|
||||
0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
|
||||
0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
|
||||
0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
|
||||
0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
|
||||
0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
|
||||
0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
|
||||
0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
|
||||
0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
|
||||
0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
|
||||
0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
|
||||
0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
|
||||
0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
|
||||
0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
|
||||
0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
|
||||
0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
|
||||
0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
|
||||
0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
|
||||
0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
|
||||
0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
|
||||
0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
|
||||
0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
|
||||
0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
|
||||
0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
|
||||
0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
|
||||
0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
|
||||
0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
|
||||
0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
|
||||
0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
|
||||
0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
|
||||
0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
|
||||
0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
|
||||
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
|
||||
};
|
||||
const u32 Td2[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
|
||||
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
|
||||
0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
|
||||
0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
|
||||
0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
|
||||
0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
|
||||
0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
|
||||
0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
|
||||
0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
|
||||
0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
|
||||
0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
|
||||
0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
|
||||
0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
|
||||
0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
|
||||
0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
|
||||
0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
|
||||
0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
|
||||
0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
|
||||
0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
|
||||
0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
|
||||
|
||||
0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
|
||||
0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
|
||||
0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
|
||||
0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
|
||||
0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
|
||||
0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
|
||||
0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
|
||||
0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
|
||||
0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
|
||||
0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
|
||||
0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
|
||||
0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
|
||||
0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
|
||||
0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
|
||||
0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
|
||||
0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
|
||||
0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
|
||||
0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
|
||||
0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
|
||||
0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
|
||||
0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
|
||||
0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
|
||||
0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
|
||||
0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
|
||||
0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
|
||||
0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
|
||||
0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
|
||||
0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
|
||||
0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
|
||||
0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
|
||||
0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
|
||||
0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
|
||||
0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
|
||||
0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
|
||||
0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
|
||||
0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
|
||||
0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
|
||||
0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
|
||||
0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
|
||||
0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
|
||||
0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
|
||||
0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
|
||||
0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
|
||||
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
|
||||
};
|
||||
const u32 Td3[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
|
||||
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
|
||||
0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
|
||||
0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
|
||||
0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
|
||||
0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
|
||||
0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
|
||||
0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
|
||||
0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
|
||||
0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
|
||||
0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
|
||||
0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
|
||||
0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
|
||||
0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
|
||||
0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
|
||||
0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
|
||||
0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
|
||||
0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
|
||||
0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
|
||||
0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
|
||||
0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
|
||||
0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
|
||||
0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
|
||||
0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
|
||||
0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
|
||||
0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
|
||||
0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
|
||||
0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
|
||||
0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
|
||||
0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
|
||||
0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
|
||||
0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
|
||||
0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
|
||||
0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
|
||||
0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
|
||||
0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
|
||||
0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
|
||||
0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
|
||||
0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
|
||||
0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
|
||||
0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
|
||||
0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
|
||||
0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
|
||||
0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
|
||||
0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
|
||||
0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
|
||||
0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
|
||||
0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
|
||||
0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
|
||||
0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
|
||||
0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
|
||||
0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
|
||||
0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
|
||||
0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
|
||||
0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
|
||||
0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
|
||||
0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
|
||||
0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
|
||||
0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
|
||||
0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
|
||||
0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
|
||||
0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
|
||||
0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
|
||||
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
|
||||
};
|
||||
const u32 Td4[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
|
||||
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
|
||||
0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
|
||||
0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
|
||||
0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
|
||||
0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
|
||||
0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
|
||||
0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
|
||||
0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
|
||||
0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
|
||||
0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
|
||||
0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
|
||||
0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
|
||||
0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
|
||||
0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
|
||||
0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
|
||||
0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
|
||||
0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
|
||||
0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
|
||||
0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
|
||||
0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
|
||||
0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
|
||||
0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
|
||||
0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
|
||||
0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
|
||||
0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
|
||||
0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
|
||||
0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
|
||||
0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
|
||||
0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
|
||||
0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
|
||||
0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
|
||||
0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
|
||||
0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
|
||||
0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
|
||||
0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
|
||||
0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
|
||||
0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
|
||||
0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
|
||||
0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
|
||||
0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
|
||||
0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
|
||||
0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
|
||||
0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
|
||||
0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
|
||||
0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
|
||||
0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
|
||||
0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
|
||||
0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
|
||||
0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
|
||||
0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
|
||||
0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
|
||||
0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
|
||||
0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
|
||||
0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
|
||||
0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
|
||||
0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
|
||||
0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
|
||||
0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
|
||||
0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
|
||||
0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
|
||||
0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
|
||||
0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
|
||||
0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
|
||||
};
|
||||
const u32 rcon[] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x01000000, 0x02000000, 0x04000000, 0x08000000,
|
||||
0x10000000, 0x20000000, 0x40000000, 0x80000000,
|
||||
0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
|
||||
};
|
||||
#else /* AES_SMALL_TABLES */
|
||||
const u8 Td4s[256] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U,
|
||||
0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU,
|
||||
0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U,
|
||||
0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU,
|
||||
0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU,
|
||||
0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU,
|
||||
0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U,
|
||||
0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U,
|
||||
0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U,
|
||||
0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U,
|
||||
0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU,
|
||||
0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U,
|
||||
0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU,
|
||||
0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U,
|
||||
0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U,
|
||||
0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU,
|
||||
0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU,
|
||||
0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U,
|
||||
0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U,
|
||||
0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU,
|
||||
0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U,
|
||||
0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU,
|
||||
0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U,
|
||||
0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U,
|
||||
0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U,
|
||||
0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU,
|
||||
0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU,
|
||||
0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU,
|
||||
0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U,
|
||||
0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U,
|
||||
0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U,
|
||||
0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU,
|
||||
};
|
||||
const u8 rcons[] /* ICACHE_RODATA_ATTR */ = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36
|
||||
/* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
|
||||
};
|
||||
#endif /* AES_SMALL_TABLES */
|
||||
/**
|
||||
* Expand the cipher key into the encryption key schedule.
|
||||
*
|
||||
* @return the number of rounds for the given cipher key size.
|
||||
*/
|
||||
int wpa_rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits)
|
||||
{
|
||||
int i;
|
||||
u32 temp;
|
||||
|
||||
rk[0] = GETU32(cipherKey );
|
||||
rk[1] = GETU32(cipherKey + 4);
|
||||
rk[2] = GETU32(cipherKey + 8);
|
||||
rk[3] = GETU32(cipherKey + 12);
|
||||
|
||||
if (keyBits == 128) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
temp = rk[3];
|
||||
rk[4] = rk[0] ^ TE421(temp) ^ TE432(temp) ^
|
||||
TE443(temp) ^ TE414(temp) ^ RCON(i);
|
||||
rk[5] = rk[1] ^ rk[4];
|
||||
rk[6] = rk[2] ^ rk[5];
|
||||
rk[7] = rk[3] ^ rk[6];
|
||||
rk += 4;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
|
||||
rk[4] = GETU32(cipherKey + 16);
|
||||
rk[5] = GETU32(cipherKey + 20);
|
||||
|
||||
if (keyBits == 192) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
temp = rk[5];
|
||||
rk[6] = rk[0] ^ TE421(temp) ^ TE432(temp) ^
|
||||
TE443(temp) ^ TE414(temp) ^ RCON(i);
|
||||
rk[7] = rk[1] ^ rk[6];
|
||||
rk[8] = rk[2] ^ rk[7];
|
||||
rk[9] = rk[3] ^ rk[8];
|
||||
if (i == 7)
|
||||
return 12;
|
||||
rk[10] = rk[4] ^ rk[9];
|
||||
rk[11] = rk[5] ^ rk[10];
|
||||
rk += 6;
|
||||
}
|
||||
}
|
||||
|
||||
rk[6] = GETU32(cipherKey + 24);
|
||||
rk[7] = GETU32(cipherKey + 28);
|
||||
|
||||
if (keyBits == 256) {
|
||||
for (i = 0; i < 7; i++) {
|
||||
temp = rk[7];
|
||||
rk[8] = rk[0] ^ TE421(temp) ^ TE432(temp) ^
|
||||
TE443(temp) ^ TE414(temp) ^ RCON(i);
|
||||
rk[9] = rk[1] ^ rk[8];
|
||||
rk[10] = rk[2] ^ rk[9];
|
||||
rk[11] = rk[3] ^ rk[10];
|
||||
if (i == 6)
|
||||
return 14;
|
||||
temp = rk[11];
|
||||
rk[12] = rk[4] ^ TE411(temp) ^ TE422(temp) ^
|
||||
TE433(temp) ^ TE444(temp);
|
||||
rk[13] = rk[5] ^ rk[12];
|
||||
rk[14] = rk[6] ^ rk[13];
|
||||
rk[15] = rk[7] ^ rk[14];
|
||||
rk += 8;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
80
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-unwrap.c
vendored
Normal file
80
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-unwrap.c
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* AES key unwrap (128-bit KEK, RFC3394)
|
||||
*
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/aes.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
|
||||
/**
|
||||
* aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
|
||||
* @kek: Key encryption key (KEK)
|
||||
* @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
|
||||
* bytes
|
||||
* @cipher: Wrapped key to be unwrapped, (n + 1) * 64 bits
|
||||
* @plain: Plaintext key, n * 64 bits
|
||||
* Returns: 0 on success, -1 on failure (e.g., integrity verification failed)
|
||||
*/
|
||||
int
|
||||
wpa_aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
|
||||
{
|
||||
u8 a[8], *r, b[16];
|
||||
int i, j;
|
||||
void *ctx;
|
||||
|
||||
/* 1) Initialize variables. */
|
||||
os_memcpy(a, cipher, 8);
|
||||
r = plain;
|
||||
os_memcpy(r, cipher + 8, 8 * n);
|
||||
|
||||
ctx = wpa_aes_decrypt_init(kek, 16);
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
|
||||
/* 2) Compute intermediate values.
|
||||
* For j = 5 to 0
|
||||
* For i = n to 1
|
||||
* B = AES-1(K, (A ^ t) | R[i]) where t = n*j+i
|
||||
* A = MSB(64, B)
|
||||
* R[i] = LSB(64, B)
|
||||
*/
|
||||
for (j = 5; j >= 0; j--) {
|
||||
r = plain + (n - 1) * 8;
|
||||
for (i = n; i >= 1; i--) {
|
||||
os_memcpy(b, a, 8);
|
||||
b[7] ^= n * j + i;
|
||||
|
||||
os_memcpy(b + 8, r, 8);
|
||||
wpa_aes_decrypt(ctx, b, b);
|
||||
os_memcpy(a, b, 8);
|
||||
os_memcpy(r, b + 8, 8);
|
||||
r -= 8;
|
||||
}
|
||||
}
|
||||
wpa_aes_decrypt_deinit(ctx);
|
||||
|
||||
/* 3) Output results.
|
||||
*
|
||||
* These are already in @plain due to the location of temporary
|
||||
* variables. Just verify that the IV matches with the expected value.
|
||||
*/
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (a[i] != 0xa6)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
70
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-wrap.c
vendored
Normal file
70
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/aes-wrap.c
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
|
||||
*
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/aes.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
|
||||
/**
|
||||
* aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
|
||||
* @kek: 16-octet Key encryption key (KEK)
|
||||
* @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
|
||||
* bytes
|
||||
* @plain: Plaintext key to be wrapped, n * 64 bits
|
||||
* @cipher: Wrapped key, (n + 1) * 64 bits
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int wpa_aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
|
||||
{
|
||||
u8 *a, *r, b[16];
|
||||
int i, j;
|
||||
void *ctx;
|
||||
|
||||
a = cipher;
|
||||
r = cipher + 8;
|
||||
|
||||
/* 1) Initialize variables. */
|
||||
os_memset(a, 0xa6, 8);
|
||||
os_memcpy(r, plain, 8 * n);
|
||||
|
||||
ctx = wpa_aes_encrypt_init(kek, 16);
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
|
||||
/* 2) Calculate intermediate values.
|
||||
* For j = 0 to 5
|
||||
* For i=1 to n
|
||||
* B = AES(K, A | R[i])
|
||||
* A = MSB(64, B) ^ t where t = (n*j)+i
|
||||
* R[i] = LSB(64, B)
|
||||
*/
|
||||
for (j = 0; j <= 5; j++) {
|
||||
r = cipher + 8;
|
||||
for (i = 1; i <= n; i++) {
|
||||
os_memcpy(b, a, 8);
|
||||
os_memcpy(b + 8, r, 8);
|
||||
wpa_aes_encrypt(ctx, b, b);
|
||||
os_memcpy(a, b, 8);
|
||||
a[7] ^= n * j + i;
|
||||
os_memcpy(r, b + 8, 8);
|
||||
r += 8;
|
||||
}
|
||||
}
|
||||
wpa_aes_encrypt_deinit(ctx);
|
||||
|
||||
/* 3) Output the results.
|
||||
*
|
||||
* These are already in @cipher due to the location of temporary
|
||||
* variables.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
244
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/bignum.c
vendored
Normal file
244
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/bignum.c
vendored
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Big number math
|
||||
* Copyright (c) 2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "wpa/wpabuf.h"
|
||||
#include "wpa/wpa_debug.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#define CONFIG_INTERNAL_LIBTOMMATH
|
||||
#ifdef CONFIG_INTERNAL_LIBTOMMATH
|
||||
#include "libtommath.h"
|
||||
#else /* CONFIG_INTERNAL_LIBTOMMATH */
|
||||
#include <tommath.h>
|
||||
#endif /* CONFIG_INTERNAL_LIBTOMMATH */
|
||||
|
||||
|
||||
/*
|
||||
* The current version is just a wrapper for LibTomMath library, so
|
||||
* struct bignum is just typecast to mp_int.
|
||||
*/
|
||||
|
||||
/**
|
||||
* bignum_init - Allocate memory for bignum
|
||||
* Returns: Pointer to allocated bignum or %NULL on failure
|
||||
*/
|
||||
struct bignum *
|
||||
bignum_init(void)
|
||||
{
|
||||
struct bignum *n = (struct bignum *)os_zalloc(sizeof(mp_int));
|
||||
if (n == NULL)
|
||||
return NULL;
|
||||
if (mp_init((mp_int *) n) != MP_OKAY) {
|
||||
os_free(n);
|
||||
n = NULL;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_deinit - Free bignum
|
||||
* @n: Bignum from bignum_init()
|
||||
*/
|
||||
void
|
||||
bignum_deinit(struct bignum *n)
|
||||
{
|
||||
if (n) {
|
||||
mp_clear((mp_int *) n);
|
||||
os_free(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_get_unsigned_bin - Get length of bignum as an unsigned binary buffer
|
||||
* @n: Bignum from bignum_init()
|
||||
* Returns: Length of n if written to a binary buffer
|
||||
*/
|
||||
size_t
|
||||
bignum_get_unsigned_bin_len(struct bignum *n)
|
||||
{
|
||||
return mp_unsigned_bin_size((mp_int *) n);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_get_unsigned_bin - Set binary buffer to unsigned bignum
|
||||
* @n: Bignum from bignum_init()
|
||||
* @buf: Buffer for the binary number
|
||||
* @len: Length of the buffer, can be %NULL if buffer is known to be long
|
||||
* enough. Set to used buffer length on success if not %NULL.
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_get_unsigned_bin(const struct bignum *n, u8 *buf, size_t *len)
|
||||
{
|
||||
size_t need = mp_unsigned_bin_size((mp_int *) n);
|
||||
if (len && need > *len) {
|
||||
*len = need;
|
||||
return -1;
|
||||
}
|
||||
if (mp_to_unsigned_bin((mp_int *) n, buf) != MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
if (len)
|
||||
*len = need;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_set_unsigned_bin - Set bignum based on unsigned binary buffer
|
||||
* @n: Bignum from bignum_init(); to be set to the given value
|
||||
* @buf: Buffer with unsigned binary value
|
||||
* @len: Length of buf in octets
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_set_unsigned_bin(struct bignum *n, const u8 *buf, size_t len)
|
||||
{
|
||||
if (mp_read_unsigned_bin((mp_int *) n, (u8 *) buf, len) != MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_cmp - Signed comparison
|
||||
* @a: Bignum from bignum_init()
|
||||
* @b: Bignum from bignum_init()
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_cmp(const struct bignum *a, const struct bignum *b)
|
||||
{
|
||||
return mp_cmp((mp_int *) a, (mp_int *) b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_cmd_d - Compare bignum to standard integer
|
||||
* @a: Bignum from bignum_init()
|
||||
* @b: Small integer
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_cmp_d(const struct bignum *a, unsigned long b)
|
||||
{
|
||||
return mp_cmp_d((mp_int *) a, b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_add - c = a + b
|
||||
* @a: Bignum from bignum_init()
|
||||
* @b: Bignum from bignum_init()
|
||||
* @c: Bignum from bignum_init(); used to store the result of a + b
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_add(const struct bignum *a, const struct bignum *b,
|
||||
struct bignum *c)
|
||||
{
|
||||
if (mp_add((mp_int *) a, (mp_int *) b, (mp_int *) c) != MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_sub - c = a - b
|
||||
* @a: Bignum from bignum_init()
|
||||
* @b: Bignum from bignum_init()
|
||||
* @c: Bignum from bignum_init(); used to store the result of a - b
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_sub(const struct bignum *a, const struct bignum *b,
|
||||
struct bignum *c)
|
||||
{
|
||||
if (mp_sub((mp_int *) a, (mp_int *) b, (mp_int *) c) != MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_mul - c = a * b
|
||||
* @a: Bignum from bignum_init()
|
||||
* @b: Bignum from bignum_init()
|
||||
* @c: Bignum from bignum_init(); used to store the result of a * b
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_mul(const struct bignum *a, const struct bignum *b,
|
||||
struct bignum *c)
|
||||
{
|
||||
if (mp_mul((mp_int *) a, (mp_int *) b, (mp_int *) c) != MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_mulmod - d = a * b (mod c)
|
||||
* @a: Bignum from bignum_init()
|
||||
* @b: Bignum from bignum_init()
|
||||
* @c: Bignum from bignum_init(); modulus
|
||||
* @d: Bignum from bignum_init(); used to store the result of a * b (mod c)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_mulmod(const struct bignum *a, const struct bignum *b,
|
||||
const struct bignum *c, struct bignum *d)
|
||||
{
|
||||
if (mp_mulmod((mp_int *) a, (mp_int *) b, (mp_int *) c, (mp_int *) d)
|
||||
!= MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bignum_exptmod - Modular exponentiation: d = a^b (mod c)
|
||||
* @a: Bignum from bignum_init(); base
|
||||
* @b: Bignum from bignum_init(); exponent
|
||||
* @c: Bignum from bignum_init(); modulus
|
||||
* @d: Bignum from bignum_init(); used to store the result of a^b (mod c)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
bignum_exptmod(const struct bignum *a, const struct bignum *b,
|
||||
const struct bignum *c, struct bignum *d)
|
||||
{
|
||||
if (mp_exptmod((mp_int *) a, (mp_int *) b, (mp_int *) c, (mp_int *) d)
|
||||
!= MP_OKAY) {
|
||||
wpa_printf(MSG_DEBUG, "BIGNUM: %s failed", __func__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
38
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/bignum.h
vendored
Normal file
38
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/bignum.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Big number math
|
||||
* Copyright (c) 2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef BIGNUM_H
|
||||
#define BIGNUM_H
|
||||
|
||||
struct bignum;
|
||||
|
||||
struct bignum * bignum_init(void);
|
||||
void bignum_deinit(struct bignum *n);
|
||||
size_t bignum_get_unsigned_bin_len(struct bignum *n);
|
||||
int bignum_get_unsigned_bin(const struct bignum *n, u8 *buf, size_t *len);
|
||||
int bignum_set_unsigned_bin(struct bignum *n, const u8 *buf, size_t len);
|
||||
int bignum_cmp(const struct bignum *a, const struct bignum *b);
|
||||
int bignum_cmp_d(const struct bignum *a, unsigned long b);
|
||||
int bignum_add(const struct bignum *a, const struct bignum *b,
|
||||
struct bignum *c);
|
||||
int bignum_sub(const struct bignum *a, const struct bignum *b,
|
||||
struct bignum *c);
|
||||
int bignum_mul(const struct bignum *a, const struct bignum *b,
|
||||
struct bignum *c);
|
||||
int bignum_mulmod(const struct bignum *a, const struct bignum *b,
|
||||
const struct bignum *c, struct bignum *d);
|
||||
int bignum_exptmod(const struct bignum *a, const struct bignum *b,
|
||||
const struct bignum *c, struct bignum *d);
|
||||
|
||||
#endif /* BIGNUM_H */
|
56
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/crypto_internal-modexp.c
vendored
Normal file
56
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/crypto_internal-modexp.c
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Crypto wrapper for internal crypto implementation - modexp
|
||||
* Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "bignum.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
||||
int
|
||||
crypto_mod_exp(const u8 *base, size_t base_len,
|
||||
const u8 *power, size_t power_len,
|
||||
const u8 *modulus, size_t modulus_len,
|
||||
u8 *result, size_t *result_len)
|
||||
{
|
||||
struct bignum *bn_base, *bn_exp, *bn_modulus, *bn_result;
|
||||
int ret = -1;
|
||||
|
||||
bn_base = bignum_init();
|
||||
bn_exp = bignum_init();
|
||||
bn_modulus = bignum_init();
|
||||
bn_result = bignum_init();
|
||||
|
||||
if (bn_base == NULL || bn_exp == NULL || bn_modulus == NULL ||
|
||||
bn_result == NULL)
|
||||
goto error;
|
||||
|
||||
if (bignum_set_unsigned_bin(bn_base, base, base_len) < 0 ||
|
||||
bignum_set_unsigned_bin(bn_exp, power, power_len) < 0 ||
|
||||
bignum_set_unsigned_bin(bn_modulus, modulus, modulus_len) < 0)
|
||||
goto error;
|
||||
|
||||
if (bignum_exptmod(bn_base, bn_exp, bn_modulus, bn_result) < 0)
|
||||
goto error;
|
||||
|
||||
ret = bignum_get_unsigned_bin(bn_result, result, result_len);
|
||||
|
||||
error:
|
||||
bignum_deinit(bn_base);
|
||||
bignum_deinit(bn_exp);
|
||||
bignum_deinit(bn_modulus);
|
||||
bignum_deinit(bn_result);
|
||||
return ret;
|
||||
}
|
43
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/dh_group5.c
vendored
Normal file
43
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/dh_group5.c
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Diffie-Hellman group 5 operations
|
||||
* Copyright (c) 2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/dh_groups.h"
|
||||
#include "crypto/dh_group5.h"
|
||||
|
||||
|
||||
void *
|
||||
wpa_dh5_init(struct wpabuf **priv, struct wpabuf **publ)
|
||||
{
|
||||
*publ = wpa_dh_init(wpa_dh_groups_get(5), priv);
|
||||
if (*publ == 0)
|
||||
return NULL;
|
||||
return (void *) 1;
|
||||
}
|
||||
|
||||
|
||||
struct wpabuf *
|
||||
wpa_dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
|
||||
const struct wpabuf *own_private)
|
||||
{
|
||||
return wpa_dh_derive_shared(peer_public, own_private, wpa_dh_groups_get(5));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wpa_dh5_free(void *ctx)
|
||||
{
|
||||
}
|
641
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/dh_groups.c
vendored
Normal file
641
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/dh_groups.c
vendored
Normal file
@ -0,0 +1,641 @@
|
||||
/*
|
||||
* Diffie-Hellman groups
|
||||
* Copyright (c) 2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/random.h"
|
||||
#include "crypto/dh_groups.h"
|
||||
#include "wpa/wpabuf.h"
|
||||
#include "wpa/wpa_debug.h"
|
||||
|
||||
extern int crypto_mod_exp(const u8 *base, size_t base_len,
|
||||
const u8 *power, size_t power_len,
|
||||
const u8 *modulus, size_t modulus_len,
|
||||
u8 *result, size_t *result_len);
|
||||
|
||||
#ifdef ALL_DH_GROUPS
|
||||
|
||||
/* RFC 4306, B.1. Group 1 - 768 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 }
|
||||
*/
|
||||
static const u8 dh_group1_generator[1] = { 0x02 };
|
||||
static const u8 dh_group1_prime[96] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x3A, 0x36, 0x20,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
/* RFC 4306, B.2. Group 2 - 1024 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 }
|
||||
*/
|
||||
static const u8 dh_group2_generator[1] = { 0x02 };
|
||||
static const u8 dh_group2_prime[128] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
#endif /* ALL_DH_GROUPS */
|
||||
|
||||
/* RFC 3526, 2. Group 5 - 1536 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^1536 - 2^1472 - 1 + 2^64 * { [2^1406 pi] + 741804 }
|
||||
*/
|
||||
static const u8 dh_group5_generator[1] = { 0x02 };
|
||||
static const u8 dh_group5_prime[192] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
||||
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
|
||||
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
|
||||
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
|
||||
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
|
||||
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
|
||||
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
|
||||
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
|
||||
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x23, 0x73, 0x27,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
#ifdef ALL_DH_GROUPS
|
||||
|
||||
/* RFC 3526, 3. Group 14 - 2048 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 }
|
||||
*/
|
||||
static const u8 dh_group14_generator[1] = { 0x02 };
|
||||
static const u8 dh_group14_prime[256] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
||||
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
|
||||
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
|
||||
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
|
||||
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
|
||||
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
|
||||
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
|
||||
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
|
||||
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C,
|
||||
0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
|
||||
0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03,
|
||||
0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
|
||||
0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
|
||||
0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
|
||||
0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5,
|
||||
0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
|
||||
0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
/* RFC 3526, 4. Group 15 - 3072 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^3072 - 2^3008 - 1 + 2^64 * { [2^2942 pi] + 1690314 }
|
||||
*/
|
||||
static const u8 dh_group15_generator[1] = { 0x02 };
|
||||
static const u8 dh_group15_prime[384] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
||||
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
|
||||
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
|
||||
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
|
||||
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
|
||||
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
|
||||
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
|
||||
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
|
||||
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C,
|
||||
0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
|
||||
0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03,
|
||||
0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
|
||||
0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
|
||||
0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
|
||||
0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5,
|
||||
0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
|
||||
0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D,
|
||||
0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33,
|
||||
0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64,
|
||||
0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A,
|
||||
0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D,
|
||||
0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
|
||||
0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7,
|
||||
0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D,
|
||||
0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B,
|
||||
0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64,
|
||||
0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64,
|
||||
0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
|
||||
0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C,
|
||||
0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2,
|
||||
0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
|
||||
0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E,
|
||||
0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
/* RFC 3526, 5. Group 16 - 4096 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^4096 - 2^4032 - 1 + 2^64 * { [2^3966 pi] + 240904 }
|
||||
*/
|
||||
static const u8 dh_group16_generator[1] = { 0x02 };
|
||||
static const u8 dh_group16_prime[512] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
||||
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
|
||||
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
|
||||
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
|
||||
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
|
||||
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
|
||||
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
|
||||
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
|
||||
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C,
|
||||
0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
|
||||
0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03,
|
||||
0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
|
||||
0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
|
||||
0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
|
||||
0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5,
|
||||
0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
|
||||
0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D,
|
||||
0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33,
|
||||
0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64,
|
||||
0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A,
|
||||
0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D,
|
||||
0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
|
||||
0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7,
|
||||
0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D,
|
||||
0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B,
|
||||
0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64,
|
||||
0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64,
|
||||
0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
|
||||
0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C,
|
||||
0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2,
|
||||
0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
|
||||
0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E,
|
||||
0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01,
|
||||
0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7,
|
||||
0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26,
|
||||
0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C,
|
||||
0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA,
|
||||
0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8,
|
||||
0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9,
|
||||
0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6,
|
||||
0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D,
|
||||
0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2,
|
||||
0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED,
|
||||
0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF,
|
||||
0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C,
|
||||
0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
|
||||
0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1,
|
||||
0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F,
|
||||
0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
/* RFC 3526, 6. Group 17 - 6144 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^6144 - 2^6080 - 1 + 2^64 * { [2^6014 pi] + 929484 }
|
||||
*/
|
||||
static const u8 dh_group17_generator[1] = { 0x02 };
|
||||
static const u8 dh_group17_prime[768] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
||||
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
|
||||
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
|
||||
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
|
||||
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
|
||||
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
|
||||
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
|
||||
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
|
||||
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C,
|
||||
0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
|
||||
0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03,
|
||||
0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
|
||||
0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
|
||||
0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
|
||||
0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5,
|
||||
0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
|
||||
0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D,
|
||||
0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33,
|
||||
0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64,
|
||||
0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A,
|
||||
0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D,
|
||||
0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
|
||||
0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7,
|
||||
0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D,
|
||||
0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B,
|
||||
0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64,
|
||||
0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64,
|
||||
0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
|
||||
0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C,
|
||||
0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2,
|
||||
0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
|
||||
0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E,
|
||||
0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01,
|
||||
0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7,
|
||||
0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26,
|
||||
0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C,
|
||||
0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA,
|
||||
0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8,
|
||||
0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9,
|
||||
0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6,
|
||||
0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D,
|
||||
0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2,
|
||||
0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED,
|
||||
0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF,
|
||||
0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C,
|
||||
0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
|
||||
0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1,
|
||||
0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F,
|
||||
0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x02, 0x84, 0x92,
|
||||
0x36, 0xC3, 0xFA, 0xB4, 0xD2, 0x7C, 0x70, 0x26,
|
||||
0xC1, 0xD4, 0xDC, 0xB2, 0x60, 0x26, 0x46, 0xDE,
|
||||
0xC9, 0x75, 0x1E, 0x76, 0x3D, 0xBA, 0x37, 0xBD,
|
||||
0xF8, 0xFF, 0x94, 0x06, 0xAD, 0x9E, 0x53, 0x0E,
|
||||
0xE5, 0xDB, 0x38, 0x2F, 0x41, 0x30, 0x01, 0xAE,
|
||||
0xB0, 0x6A, 0x53, 0xED, 0x90, 0x27, 0xD8, 0x31,
|
||||
0x17, 0x97, 0x27, 0xB0, 0x86, 0x5A, 0x89, 0x18,
|
||||
0xDA, 0x3E, 0xDB, 0xEB, 0xCF, 0x9B, 0x14, 0xED,
|
||||
0x44, 0xCE, 0x6C, 0xBA, 0xCE, 0xD4, 0xBB, 0x1B,
|
||||
0xDB, 0x7F, 0x14, 0x47, 0xE6, 0xCC, 0x25, 0x4B,
|
||||
0x33, 0x20, 0x51, 0x51, 0x2B, 0xD7, 0xAF, 0x42,
|
||||
0x6F, 0xB8, 0xF4, 0x01, 0x37, 0x8C, 0xD2, 0xBF,
|
||||
0x59, 0x83, 0xCA, 0x01, 0xC6, 0x4B, 0x92, 0xEC,
|
||||
0xF0, 0x32, 0xEA, 0x15, 0xD1, 0x72, 0x1D, 0x03,
|
||||
0xF4, 0x82, 0xD7, 0xCE, 0x6E, 0x74, 0xFE, 0xF6,
|
||||
0xD5, 0x5E, 0x70, 0x2F, 0x46, 0x98, 0x0C, 0x82,
|
||||
0xB5, 0xA8, 0x40, 0x31, 0x90, 0x0B, 0x1C, 0x9E,
|
||||
0x59, 0xE7, 0xC9, 0x7F, 0xBE, 0xC7, 0xE8, 0xF3,
|
||||
0x23, 0xA9, 0x7A, 0x7E, 0x36, 0xCC, 0x88, 0xBE,
|
||||
0x0F, 0x1D, 0x45, 0xB7, 0xFF, 0x58, 0x5A, 0xC5,
|
||||
0x4B, 0xD4, 0x07, 0xB2, 0x2B, 0x41, 0x54, 0xAA,
|
||||
0xCC, 0x8F, 0x6D, 0x7E, 0xBF, 0x48, 0xE1, 0xD8,
|
||||
0x14, 0xCC, 0x5E, 0xD2, 0x0F, 0x80, 0x37, 0xE0,
|
||||
0xA7, 0x97, 0x15, 0xEE, 0xF2, 0x9B, 0xE3, 0x28,
|
||||
0x06, 0xA1, 0xD5, 0x8B, 0xB7, 0xC5, 0xDA, 0x76,
|
||||
0xF5, 0x50, 0xAA, 0x3D, 0x8A, 0x1F, 0xBF, 0xF0,
|
||||
0xEB, 0x19, 0xCC, 0xB1, 0xA3, 0x13, 0xD5, 0x5C,
|
||||
0xDA, 0x56, 0xC9, 0xEC, 0x2E, 0xF2, 0x96, 0x32,
|
||||
0x38, 0x7F, 0xE8, 0xD7, 0x6E, 0x3C, 0x04, 0x68,
|
||||
0x04, 0x3E, 0x8F, 0x66, 0x3F, 0x48, 0x60, 0xEE,
|
||||
0x12, 0xBF, 0x2D, 0x5B, 0x0B, 0x74, 0x74, 0xD6,
|
||||
0xE6, 0x94, 0xF9, 0x1E, 0x6D, 0xCC, 0x40, 0x24,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
/* RFC 3526, 7. Group 18 - 8192 Bit MODP
|
||||
* Generator: 2
|
||||
* Prime: 2^8192 - 2^8128 - 1 + 2^64 * { [2^8062 pi] + 4743158 }
|
||||
*/
|
||||
static const u8 dh_group18_generator[1] = { 0x02 };
|
||||
static const u8 dh_group18_prime[1024] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
|
||||
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
|
||||
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
|
||||
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
||||
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
|
||||
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
|
||||
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
||||
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
|
||||
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
|
||||
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
||||
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
|
||||
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
|
||||
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
||||
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
|
||||
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
|
||||
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
|
||||
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
|
||||
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
|
||||
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
|
||||
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
|
||||
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C,
|
||||
0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
|
||||
0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03,
|
||||
0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
|
||||
0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
|
||||
0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
|
||||
0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5,
|
||||
0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
|
||||
0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D,
|
||||
0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33,
|
||||
0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64,
|
||||
0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A,
|
||||
0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D,
|
||||
0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
|
||||
0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7,
|
||||
0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D,
|
||||
0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B,
|
||||
0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64,
|
||||
0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64,
|
||||
0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
|
||||
0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C,
|
||||
0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2,
|
||||
0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
|
||||
0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E,
|
||||
0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01,
|
||||
0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7,
|
||||
0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26,
|
||||
0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C,
|
||||
0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA,
|
||||
0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8,
|
||||
0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9,
|
||||
0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6,
|
||||
0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D,
|
||||
0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2,
|
||||
0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED,
|
||||
0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF,
|
||||
0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C,
|
||||
0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
|
||||
0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1,
|
||||
0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F,
|
||||
0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x02, 0x84, 0x92,
|
||||
0x36, 0xC3, 0xFA, 0xB4, 0xD2, 0x7C, 0x70, 0x26,
|
||||
0xC1, 0xD4, 0xDC, 0xB2, 0x60, 0x26, 0x46, 0xDE,
|
||||
0xC9, 0x75, 0x1E, 0x76, 0x3D, 0xBA, 0x37, 0xBD,
|
||||
0xF8, 0xFF, 0x94, 0x06, 0xAD, 0x9E, 0x53, 0x0E,
|
||||
0xE5, 0xDB, 0x38, 0x2F, 0x41, 0x30, 0x01, 0xAE,
|
||||
0xB0, 0x6A, 0x53, 0xED, 0x90, 0x27, 0xD8, 0x31,
|
||||
0x17, 0x97, 0x27, 0xB0, 0x86, 0x5A, 0x89, 0x18,
|
||||
0xDA, 0x3E, 0xDB, 0xEB, 0xCF, 0x9B, 0x14, 0xED,
|
||||
0x44, 0xCE, 0x6C, 0xBA, 0xCE, 0xD4, 0xBB, 0x1B,
|
||||
0xDB, 0x7F, 0x14, 0x47, 0xE6, 0xCC, 0x25, 0x4B,
|
||||
0x33, 0x20, 0x51, 0x51, 0x2B, 0xD7, 0xAF, 0x42,
|
||||
0x6F, 0xB8, 0xF4, 0x01, 0x37, 0x8C, 0xD2, 0xBF,
|
||||
0x59, 0x83, 0xCA, 0x01, 0xC6, 0x4B, 0x92, 0xEC,
|
||||
0xF0, 0x32, 0xEA, 0x15, 0xD1, 0x72, 0x1D, 0x03,
|
||||
0xF4, 0x82, 0xD7, 0xCE, 0x6E, 0x74, 0xFE, 0xF6,
|
||||
0xD5, 0x5E, 0x70, 0x2F, 0x46, 0x98, 0x0C, 0x82,
|
||||
0xB5, 0xA8, 0x40, 0x31, 0x90, 0x0B, 0x1C, 0x9E,
|
||||
0x59, 0xE7, 0xC9, 0x7F, 0xBE, 0xC7, 0xE8, 0xF3,
|
||||
0x23, 0xA9, 0x7A, 0x7E, 0x36, 0xCC, 0x88, 0xBE,
|
||||
0x0F, 0x1D, 0x45, 0xB7, 0xFF, 0x58, 0x5A, 0xC5,
|
||||
0x4B, 0xD4, 0x07, 0xB2, 0x2B, 0x41, 0x54, 0xAA,
|
||||
0xCC, 0x8F, 0x6D, 0x7E, 0xBF, 0x48, 0xE1, 0xD8,
|
||||
0x14, 0xCC, 0x5E, 0xD2, 0x0F, 0x80, 0x37, 0xE0,
|
||||
0xA7, 0x97, 0x15, 0xEE, 0xF2, 0x9B, 0xE3, 0x28,
|
||||
0x06, 0xA1, 0xD5, 0x8B, 0xB7, 0xC5, 0xDA, 0x76,
|
||||
0xF5, 0x50, 0xAA, 0x3D, 0x8A, 0x1F, 0xBF, 0xF0,
|
||||
0xEB, 0x19, 0xCC, 0xB1, 0xA3, 0x13, 0xD5, 0x5C,
|
||||
0xDA, 0x56, 0xC9, 0xEC, 0x2E, 0xF2, 0x96, 0x32,
|
||||
0x38, 0x7F, 0xE8, 0xD7, 0x6E, 0x3C, 0x04, 0x68,
|
||||
0x04, 0x3E, 0x8F, 0x66, 0x3F, 0x48, 0x60, 0xEE,
|
||||
0x12, 0xBF, 0x2D, 0x5B, 0x0B, 0x74, 0x74, 0xD6,
|
||||
0xE6, 0x94, 0xF9, 0x1E, 0x6D, 0xBE, 0x11, 0x59,
|
||||
0x74, 0xA3, 0x92, 0x6F, 0x12, 0xFE, 0xE5, 0xE4,
|
||||
0x38, 0x77, 0x7C, 0xB6, 0xA9, 0x32, 0xDF, 0x8C,
|
||||
0xD8, 0xBE, 0xC4, 0xD0, 0x73, 0xB9, 0x31, 0xBA,
|
||||
0x3B, 0xC8, 0x32, 0xB6, 0x8D, 0x9D, 0xD3, 0x00,
|
||||
0x74, 0x1F, 0xA7, 0xBF, 0x8A, 0xFC, 0x47, 0xED,
|
||||
0x25, 0x76, 0xF6, 0x93, 0x6B, 0xA4, 0x24, 0x66,
|
||||
0x3A, 0xAB, 0x63, 0x9C, 0x5A, 0xE4, 0xF5, 0x68,
|
||||
0x34, 0x23, 0xB4, 0x74, 0x2B, 0xF1, 0xC9, 0x78,
|
||||
0x23, 0x8F, 0x16, 0xCB, 0xE3, 0x9D, 0x65, 0x2D,
|
||||
0xE3, 0xFD, 0xB8, 0xBE, 0xFC, 0x84, 0x8A, 0xD9,
|
||||
0x22, 0x22, 0x2E, 0x04, 0xA4, 0x03, 0x7C, 0x07,
|
||||
0x13, 0xEB, 0x57, 0xA8, 0x1A, 0x23, 0xF0, 0xC7,
|
||||
0x34, 0x73, 0xFC, 0x64, 0x6C, 0xEA, 0x30, 0x6B,
|
||||
0x4B, 0xCB, 0xC8, 0x86, 0x2F, 0x83, 0x85, 0xDD,
|
||||
0xFA, 0x9D, 0x4B, 0x7F, 0xA2, 0xC0, 0x87, 0xE8,
|
||||
0x79, 0x68, 0x33, 0x03, 0xED, 0x5B, 0xDD, 0x3A,
|
||||
0x06, 0x2B, 0x3C, 0xF5, 0xB3, 0xA2, 0x78, 0xA6,
|
||||
0x6D, 0x2A, 0x13, 0xF8, 0x3F, 0x44, 0xF8, 0x2D,
|
||||
0xDF, 0x31, 0x0E, 0xE0, 0x74, 0xAB, 0x6A, 0x36,
|
||||
0x45, 0x97, 0xE8, 0x99, 0xA0, 0x25, 0x5D, 0xC1,
|
||||
0x64, 0xF3, 0x1C, 0xC5, 0x08, 0x46, 0x85, 0x1D,
|
||||
0xF9, 0xAB, 0x48, 0x19, 0x5D, 0xED, 0x7E, 0xA1,
|
||||
0xB1, 0xD5, 0x10, 0xBD, 0x7E, 0xE7, 0x4D, 0x73,
|
||||
0xFA, 0xF3, 0x6B, 0xC3, 0x1E, 0xCF, 0xA2, 0x68,
|
||||
0x35, 0x90, 0x46, 0xF4, 0xEB, 0x87, 0x9F, 0x92,
|
||||
0x40, 0x09, 0x43, 0x8B, 0x48, 0x1C, 0x6C, 0xD7,
|
||||
0x88, 0x9A, 0x00, 0x2E, 0xD5, 0xEE, 0x38, 0x2B,
|
||||
0xC9, 0x19, 0x0D, 0xA6, 0xFC, 0x02, 0x6E, 0x47,
|
||||
0x95, 0x58, 0xE4, 0x47, 0x56, 0x77, 0xE9, 0xAA,
|
||||
0x9E, 0x30, 0x50, 0xE2, 0x76, 0x56, 0x94, 0xDF,
|
||||
0xC8, 0x1F, 0x56, 0xE8, 0x80, 0xB9, 0x6E, 0x71,
|
||||
0x60, 0xC9, 0x80, 0xDD, 0x98, 0xED, 0xD3, 0xDF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
#endif /* ALL_DH_GROUPS */
|
||||
|
||||
|
||||
#define DH_GROUP(id) \
|
||||
{ id, dh_group ## id ## _generator, sizeof(dh_group ## id ## _generator), \
|
||||
dh_group ## id ## _prime, sizeof(dh_group ## id ## _prime) }
|
||||
|
||||
|
||||
static struct dh_group dh_groups[] = {
|
||||
DH_GROUP(5),
|
||||
#ifdef ALL_DH_GROUPS
|
||||
DH_GROUP(1),
|
||||
DH_GROUP(2),
|
||||
DH_GROUP(14),
|
||||
DH_GROUP(15),
|
||||
DH_GROUP(16),
|
||||
DH_GROUP(17),
|
||||
DH_GROUP(18)
|
||||
#endif /* ALL_DH_GROUPS */
|
||||
};
|
||||
|
||||
#define NUM_DH_GROUPS (sizeof(dh_groups) / sizeof(dh_groups[0]))
|
||||
|
||||
|
||||
const struct dh_group *
|
||||
wpa_dh_groups_get(int id)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < NUM_DH_GROUPS; i++) {
|
||||
if (dh_groups[i].id == id)
|
||||
return &dh_groups[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* dh_init - Initialize Diffie-Hellman handshake
|
||||
* @dh: Selected Diffie-Hellman group
|
||||
* @priv: Pointer for returning Diffie-Hellman private key
|
||||
* Returns: Diffie-Hellman public value
|
||||
*/
|
||||
struct wpabuf *
|
||||
wpa_dh_init(const struct dh_group *dh, struct wpabuf **priv)
|
||||
{
|
||||
struct wpabuf *pv;
|
||||
size_t pv_len;
|
||||
|
||||
if (dh == NULL)
|
||||
return NULL;
|
||||
|
||||
wpabuf_free(*priv);
|
||||
*priv = wpabuf_alloc(dh->prime_len);
|
||||
if (*priv == NULL)
|
||||
return NULL;
|
||||
|
||||
if (random_get_bytes(wpabuf_put(*priv, dh->prime_len), dh->prime_len))
|
||||
{
|
||||
wpabuf_free(*priv);
|
||||
*priv = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (os_memcmp(wpabuf_head(*priv), dh->prime, dh->prime_len) > 0) {
|
||||
/* Make sure private value is smaller than prime */
|
||||
*(wpabuf_mhead_u8(*priv)) = 0;
|
||||
}
|
||||
wpa_hexdump_buf_key(MSG_DEBUG, "DH: private value", *priv);
|
||||
|
||||
pv_len = dh->prime_len;
|
||||
pv = wpabuf_alloc(pv_len);
|
||||
if (pv == NULL)
|
||||
return NULL;
|
||||
if (crypto_mod_exp(dh->generator, dh->generator_len,
|
||||
wpabuf_head(*priv), wpabuf_len(*priv),
|
||||
dh->prime, dh->prime_len, wpabuf_mhead(pv),
|
||||
&pv_len) < 0) {
|
||||
wpabuf_free(pv);
|
||||
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
|
||||
return NULL;
|
||||
}
|
||||
wpabuf_put(pv, pv_len);
|
||||
wpa_hexdump_buf(MSG_DEBUG, "DH: public value", pv);
|
||||
|
||||
return pv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* dh_derive_shared - Derive shared Diffie-Hellman key
|
||||
* @peer_public: Diffie-Hellman public value from peer
|
||||
* @own_private: Diffie-Hellman private key from dh_init()
|
||||
* @dh: Selected Diffie-Hellman group
|
||||
* Returns: Diffie-Hellman shared key
|
||||
*/
|
||||
struct wpabuf *
|
||||
wpa_dh_derive_shared(const struct wpabuf *peer_public,
|
||||
const struct wpabuf *own_private,
|
||||
const struct dh_group *dh)
|
||||
{
|
||||
struct wpabuf *shared;
|
||||
size_t shared_len;
|
||||
|
||||
if (dh == NULL || peer_public == NULL || own_private == NULL)
|
||||
return NULL;
|
||||
|
||||
shared_len = dh->prime_len;
|
||||
shared = wpabuf_alloc(shared_len);
|
||||
if (shared == NULL)
|
||||
return NULL;
|
||||
if (crypto_mod_exp(wpabuf_head(peer_public), wpabuf_len(peer_public),
|
||||
wpabuf_head(own_private), wpabuf_len(own_private),
|
||||
dh->prime, dh->prime_len,
|
||||
wpabuf_mhead(shared), &shared_len) < 0) {
|
||||
wpabuf_free(shared);
|
||||
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
|
||||
return NULL;
|
||||
}
|
||||
wpabuf_put(shared, shared_len);
|
||||
wpa_hexdump_buf_key(MSG_DEBUG, "DH: shared key", shared);
|
||||
|
||||
return shared;
|
||||
}
|
3444
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/libtommath.h
vendored
Normal file
3444
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/libtommath.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
298
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/md5-internal.c
vendored
Normal file
298
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/md5-internal.c
vendored
Normal file
@ -0,0 +1,298 @@
|
||||
/*
|
||||
* MD5 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/md5.h"
|
||||
#include "crypto/md5_i.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
||||
static void wpa_MD5Transform(u32 buf[4], u32 const in[16]);
|
||||
|
||||
|
||||
typedef struct MD5Context MD5_CTX;
|
||||
|
||||
|
||||
/**
|
||||
* md5_vector - 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 of failure
|
||||
*/
|
||||
int
|
||||
wpa_md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
size_t i;
|
||||
|
||||
wpa_MD5Init(&ctx);
|
||||
for (i = 0; i < num_elem; i++)
|
||||
wpa_MD5Update(&ctx, addr[i], len[i]);
|
||||
wpa_MD5Final(mac, &ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===== start - public domain MD5 implementation ===== */
|
||||
/*
|
||||
* This code implements the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
* This code is in the public domain; do with it what you wish.
|
||||
*
|
||||
* Equivalent code is available from RSA Data Security, Inc.
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*
|
||||
* To compute the message digest of a chunk of bytes, declare an
|
||||
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||
* needed on buffers full of bytes, and then call MD5Final, which
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
#define byteReverse(buf, len) /* Nothing */
|
||||
#else
|
||||
/*
|
||||
* Note: this code is harmless on little-endian machines.
|
||||
*/
|
||||
static void byteReverse(unsigned char *buf, unsigned longs)
|
||||
{
|
||||
u32 t;
|
||||
do {
|
||||
t = (u32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
||||
((unsigned) buf[1] << 8 | buf[0]);
|
||||
*(u32 *) buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||
* initialization constants.
|
||||
*/
|
||||
void
|
||||
wpa_MD5Init(struct MD5Context *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
|
||||
ctx->bits[0] = 0;
|
||||
ctx->bits[1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update context to reflect the concatenation of another buffer full
|
||||
* of bytes.
|
||||
*/
|
||||
void
|
||||
wpa_MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
|
||||
{
|
||||
u32 t;
|
||||
|
||||
/* Update bitcount */
|
||||
|
||||
t = ctx->bits[0];
|
||||
if ((ctx->bits[0] = t + ((u32) len << 3)) < t)
|
||||
ctx->bits[1]++; /* Carry from low to high */
|
||||
ctx->bits[1] += len >> 29;
|
||||
|
||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
|
||||
/* Handle any leading odd-sized chunks */
|
||||
|
||||
if (t) {
|
||||
unsigned char *p = (unsigned char *) ctx->in + t;
|
||||
|
||||
t = 64 - t;
|
||||
if (len < t) {
|
||||
os_memcpy(p, buf, len);
|
||||
return;
|
||||
}
|
||||
os_memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
/* Process data in 64-byte chunks */
|
||||
|
||||
while (len >= 64) {
|
||||
os_memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
|
||||
os_memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
* 1 0* (64-bit count of bits processed, MSB-first)
|
||||
*/
|
||||
void
|
||||
wpa_MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
||||
{
|
||||
unsigned count;
|
||||
unsigned char *p;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
p = ctx->in + count;
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
count = 64 - 1 - count;
|
||||
|
||||
/* Pad out to 56 mod 64 */
|
||||
if (count < 8) {
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
os_memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
|
||||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
os_memset(ctx->in, 0, 56);
|
||||
} else {
|
||||
/* Pad block to 56 bytes */
|
||||
os_memset(p, 0, count - 8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
((u32 *) ctx->in)[14] = ctx->bits[0];
|
||||
((u32 *) ctx->in)[15] = ctx->bits[1];
|
||||
|
||||
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
|
||||
byteReverse((unsigned char *) ctx->buf, 4);
|
||||
os_memcpy(digest, ctx->buf, 16);
|
||||
os_memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
/* The four core functions - F1 is optimized somewhat */
|
||||
|
||||
/* #define F1(x, y, z) (x & y | ~x & z) */
|
||||
#define F1(x, y, z) (z ^ (x & (y ^ z)))
|
||||
#define F2(x, y, z) F1(z, x, y)
|
||||
#define F3(x, y, z) (x ^ y ^ z)
|
||||
#define F4(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
/* This is the central step in the MD5 algorithm. */
|
||||
#define MD5STEP(f, w, x, y, z, data, s) \
|
||||
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
|
||||
|
||||
/*
|
||||
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
||||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
static void
|
||||
wpa_MD5Transform(u32 buf[4], u32 const in[16])
|
||||
{
|
||||
register u32 a, b, c, d;
|
||||
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
/* ===== end - public domain MD5 implementation ===== */
|
113
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/md5.c
vendored
Normal file
113
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/md5.c
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* MD5 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/md5.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
||||
/**
|
||||
* hmac_md5_vector - 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
|
||||
*/
|
||||
int
|
||||
wpa_hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
u8 k_pad[64]; /* padding - key XORd with ipad/opad */
|
||||
u8 tk[16];
|
||||
const u8 *_addr[6];
|
||||
size_t i, _len[6];
|
||||
|
||||
if (num_elem > 5) {
|
||||
/*
|
||||
* Fixed limit on the number of fragments to avoid having to
|
||||
* allocate memory (which could fail).
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key = MD5(key) */
|
||||
if (key_len > 64) {
|
||||
if (wpa_md5_vector(1, &key, &key_len, tk))
|
||||
return -1;
|
||||
key = tk;
|
||||
key_len = 16;
|
||||
}
|
||||
|
||||
/* the HMAC_MD5 transform looks like:
|
||||
*
|
||||
* MD5(K XOR opad, MD5(K XOR ipad, text))
|
||||
*
|
||||
* where K is an n byte key
|
||||
* ipad is the byte 0x36 repeated 64 times
|
||||
* opad is the byte 0x5c repeated 64 times
|
||||
* and text is the data being protected */
|
||||
|
||||
/* start out by storing key in ipad */
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
|
||||
/* XOR key with ipad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
|
||||
/* perform inner MD5 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i + 1] = addr[i];
|
||||
_len[i + 1] = len[i];
|
||||
}
|
||||
if (wpa_md5_vector(1 + num_elem, _addr, _len, mac))
|
||||
return -1;
|
||||
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with opad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
|
||||
/* perform outer MD5 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
_addr[1] = mac;
|
||||
_len[1] = MD5_MAC_LEN;
|
||||
return wpa_md5_vector(2, _addr, _len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hmac_md5 - 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
|
||||
*/
|
||||
int
|
||||
wpa_hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
|
||||
u8 *mac)
|
||||
{
|
||||
return wpa_hmac_md5_vector(key, key_len, 1, &data, &data_len, mac);
|
||||
}
|
61
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/rc4.c
vendored
Normal file
61
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/rc4.c
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* RC4 stream cipher
|
||||
* Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
|
||||
|
||||
int
|
||||
wpa_rc4_skip(const u8 *key, size_t keylen, size_t skip,
|
||||
u8 *data, size_t data_len)
|
||||
{
|
||||
u32 i, j, k;
|
||||
u8 S[256], *pos;
|
||||
size_t kpos;
|
||||
|
||||
/* Setup RC4 state */
|
||||
for (i = 0; i < 256; i++)
|
||||
S[i] = i;
|
||||
j = 0;
|
||||
kpos = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
j = (j + S[i] + key[kpos]) & 0xff;
|
||||
kpos++;
|
||||
if (kpos >= keylen)
|
||||
kpos = 0;
|
||||
S_SWAP(i, j);
|
||||
}
|
||||
|
||||
/* Skip the start of the stream */
|
||||
i = j = 0;
|
||||
for (k = 0; k < skip; k++) {
|
||||
i = (i + 1) & 0xff;
|
||||
j = (j + S[i]) & 0xff;
|
||||
S_SWAP(i, j);
|
||||
}
|
||||
|
||||
/* Apply RC4 to data */
|
||||
pos = data;
|
||||
for (k = 0; k < data_len; k++) {
|
||||
i = (i + 1) & 0xff;
|
||||
j = (j + S[i]) & 0xff;
|
||||
S_SWAP(i, j);
|
||||
*pos++ ^= S[(S[i] + S[j]) & 0xff];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
322
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha1-internal.c
vendored
Normal file
322
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha1-internal.c
vendored
Normal file
@ -0,0 +1,322 @@
|
||||
/*
|
||||
* SHA1 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/sha1.h"
|
||||
#include "crypto/sha1_i.h"
|
||||
#include "crypto/md5.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
typedef struct SHA1Context SHA1_CTX;
|
||||
|
||||
void wpa_SHA1Transform(u32 state[5], const unsigned char buffer[64]);
|
||||
|
||||
|
||||
/**
|
||||
* sha1_vector - 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 of failure
|
||||
*/
|
||||
int
|
||||
wpa_sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
size_t i;
|
||||
|
||||
wpa_SHA1Init(&ctx);
|
||||
for (i = 0; i < num_elem; i++)
|
||||
wpa_SHA1Update(&ctx, addr[i], len[i]);
|
||||
wpa_SHA1Final(mac, &ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===== start - public domain SHA1 implementation ===== */
|
||||
|
||||
/*
|
||||
SHA-1 in C
|
||||
By Steve Reid <sreid@sea-to-sky.net>
|
||||
100% Public Domain
|
||||
|
||||
-----------------
|
||||
Modified 7/98
|
||||
By James H. Brown <jbrown@burgoyne.com>
|
||||
Still 100% Public Domain
|
||||
|
||||
Corrected a problem which generated improper hash values on 16 bit machines
|
||||
Routine SHA1Update changed from
|
||||
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
|
||||
len)
|
||||
to
|
||||
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
|
||||
long len)
|
||||
|
||||
The 'len' parameter was declared an int which works fine on 32 bit machines.
|
||||
However, on 16 bit machines an int is too small for the shifts being done
|
||||
against
|
||||
it. This caused the hash function to generate incorrect values if len was
|
||||
greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
|
||||
|
||||
Since the file IO in main() reads 16K at a time, any file 8K or larger would
|
||||
be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
|
||||
"a"s).
|
||||
|
||||
I also changed the declaration of variables i & j in SHA1Update to
|
||||
unsigned long from unsigned int for the same reason.
|
||||
|
||||
These changes should make no difference to any 32 bit implementations since
|
||||
an
|
||||
int and a long are the same size in those environments.
|
||||
|
||||
--
|
||||
I also corrected a few compiler warnings generated by Borland C.
|
||||
1. Added #include <process.h> for exit() prototype
|
||||
2. Removed unused variable 'j' in SHA1Final
|
||||
3. Changed exit(0) to return(0) at end of main.
|
||||
|
||||
ALL changes I made can be located by searching for comments containing 'JHB'
|
||||
-----------------
|
||||
Modified 8/98
|
||||
By Steve Reid <sreid@sea-to-sky.net>
|
||||
Still 100% public domain
|
||||
|
||||
1- Removed #include <process.h> and used return() instead of exit()
|
||||
2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
|
||||
3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
|
||||
|
||||
-----------------
|
||||
Modified 4/01
|
||||
By Saul Kravitz <Saul.Kravitz@celera.com>
|
||||
Still 100% PD
|
||||
Modified to run on Compaq Alpha hardware.
|
||||
|
||||
-----------------
|
||||
Modified 4/01
|
||||
By Jouni Malinen <j@w1.fi>
|
||||
Minor changes to match the coding style used in Dynamics.
|
||||
|
||||
Modified September 24, 2004
|
||||
By Jouni Malinen <j@w1.fi>
|
||||
Fixed alignment issue in wpa_SHA1Transform when SHA1HANDSOFF is defined.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Test Vectors (from FIPS PUB 180-1)
|
||||
"abc"
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
A million repetitions of "a"
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
/* Disable the option, and reduce memory copying */
|
||||
#define SHA1HANDSOFF
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
/* blk0() and blk() perform the initial expand. */
|
||||
/* I got the idea of expanding during the round function from SSLeay */
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
#define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \
|
||||
(rol(block->l[i], 8) & 0x00FF00FF))
|
||||
#else
|
||||
#define blk0(i) block->l[i]
|
||||
#endif
|
||||
#define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \
|
||||
block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
|
||||
|
||||
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
||||
#define R0(v,w,x,y,z,i) \
|
||||
z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
|
||||
w = rol(w, 30);
|
||||
#define R1(v,w,x,y,z,i) \
|
||||
z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
|
||||
w = rol(w, 30);
|
||||
#define R2(v,w,x,y,z,i) \
|
||||
z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
|
||||
#define R3(v,w,x,y,z,i) \
|
||||
z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
|
||||
w = rol(w, 30);
|
||||
#define R4(v,w,x,y,z,i) \
|
||||
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
|
||||
w=rol(w, 30);
|
||||
|
||||
|
||||
#ifdef VERBOSE /* SAK */
|
||||
void wpa_SHAPrintContext(SHA1_CTX *context, char *msg)
|
||||
{
|
||||
printf("%s (%d,%d) %x %x %x %x %x\n",
|
||||
msg,
|
||||
context->count[0], context->count[1],
|
||||
context->state[0],
|
||||
context->state[1],
|
||||
context->state[2],
|
||||
context->state[3],
|
||||
context->state[4]);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
||||
|
||||
void
|
||||
wpa_SHA1Transform(u32 state[5], const unsigned char buffer[64])
|
||||
{
|
||||
u32 a, b, c, d, e;
|
||||
typedef union {
|
||||
unsigned char c[64];
|
||||
u32 l[16];
|
||||
} CHAR64LONG16;
|
||||
CHAR64LONG16* block;
|
||||
#ifdef SHA1HANDSOFF
|
||||
CHAR64LONG16 workspace;
|
||||
block = &workspace;
|
||||
os_memcpy(block, buffer, 64);
|
||||
#else
|
||||
block = (CHAR64LONG16 *) buffer;
|
||||
#endif
|
||||
/* Copy context->state[] to working vars */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
/* 4 rounds of 20 operations each. Loop unrolled. */
|
||||
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
||||
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
||||
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
||||
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
||||
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
||||
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
||||
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
||||
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
||||
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
||||
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
||||
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
||||
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
||||
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
||||
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
||||
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
||||
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
||||
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
||||
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
||||
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
||||
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
||||
/* Add the working vars back into context.state[] */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
|
||||
/* Wipe variables */
|
||||
/* Disable to reduce memory copying */
|
||||
//a = b = c = d = e = 0;
|
||||
#ifdef SHA1HANDSOFF
|
||||
//os_memset(block, 0, 64);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* SHA1Init - Initialize new context */
|
||||
|
||||
void
|
||||
wpa_SHA1Init(SHA1_CTX* context)
|
||||
{
|
||||
/* SHA1 initialization constants */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xEFCDAB89;
|
||||
context->state[2] = 0x98BADCFE;
|
||||
context->state[3] = 0x10325476;
|
||||
context->state[4] = 0xC3D2E1F0;
|
||||
context->count[0] = context->count[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Run your data through this. */
|
||||
|
||||
void
|
||||
wpa_SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
|
||||
{
|
||||
u32 i, j;
|
||||
const unsigned char *data = _data;
|
||||
|
||||
#ifdef VERBOSE
|
||||
SHAPrintContext(context, "before");
|
||||
#endif
|
||||
j = (context->count[0] >> 3) & 63;
|
||||
if ((context->count[0] += len << 3) < (len << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += (len >> 29);
|
||||
if ((j + len) > 63) {
|
||||
os_memcpy(&context->buffer[j], data, (i = 64-j));
|
||||
wpa_SHA1Transform(context->state, context->buffer);
|
||||
for ( ; i + 63 < len; i += 64) {
|
||||
wpa_SHA1Transform(context->state, &data[i]);
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
else i = 0;
|
||||
os_memcpy(&context->buffer[j], &data[i], len - i);
|
||||
#ifdef VERBOSE
|
||||
SHAPrintContext(context, "after ");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Add padding and return the message digest. */
|
||||
|
||||
void
|
||||
wpa_SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
||||
{
|
||||
u32 i;
|
||||
unsigned long index;
|
||||
unsigned char finalcount[8];
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
finalcount[i] = (unsigned char)
|
||||
((context->count[(i >= 4 ? 0 : 1)] >>
|
||||
((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
||||
}
|
||||
|
||||
index = 0x80;
|
||||
wpa_SHA1Update(context, (unsigned char *)&index, 1);
|
||||
|
||||
while ((context->count[0] & 504) != 448) {
|
||||
index = 0;
|
||||
wpa_SHA1Update(context, (unsigned char *)&index, 1);
|
||||
}
|
||||
wpa_SHA1Update(context, finalcount, 8); /* Should cause a wpa_SHA1Transform()
|
||||
*/
|
||||
for (i = 0; i < 20; i++) {
|
||||
digest[i] = (unsigned char)
|
||||
((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) &
|
||||
255);
|
||||
}
|
||||
/* Wipe variables */
|
||||
/* Disable here to reduce memory copying */
|
||||
// i = 0;
|
||||
// os_memset(context->buffer, 0, 64);
|
||||
// os_memset(context->state, 0, 20);
|
||||
// os_memset(context->count, 0, 8);
|
||||
// os_memset(finalcount, 0, 8);
|
||||
}
|
||||
|
||||
/* ===== end - public domain SHA1 implementation ===== */
|
101
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha1-pbkdf2.c
vendored
Normal file
101
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha1-pbkdf2.c
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* SHA1-based key derivation function (PBKDF2) for IEEE 802.11i
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/sha1.h"
|
||||
#include "crypto/md5.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
static int
|
||||
wpa_pbkdf2_sha1_f(const char *passphrase, const char *ssid,
|
||||
size_t ssid_len, int iterations, unsigned int count,
|
||||
u8 *digest)
|
||||
{
|
||||
unsigned char tmp[SHA1_MAC_LEN], tmp2[SHA1_MAC_LEN];
|
||||
int i, j;
|
||||
unsigned char count_buf[4];
|
||||
const u8 *addr[2];
|
||||
size_t len[2];
|
||||
size_t passphrase_len = os_strlen(passphrase);
|
||||
|
||||
addr[0] = (u8 *) ssid;
|
||||
len[0] = ssid_len;
|
||||
addr[1] = count_buf;
|
||||
len[1] = 4;
|
||||
|
||||
/* F(P, S, c, i) = U1 xor U2 xor ... Uc
|
||||
* U1 = PRF(P, S || i)
|
||||
* U2 = PRF(P, U1)
|
||||
* Uc = PRF(P, Uc-1)
|
||||
*/
|
||||
|
||||
count_buf[0] = (count >> 24) & 0xff;
|
||||
count_buf[1] = (count >> 16) & 0xff;
|
||||
count_buf[2] = (count >> 8) & 0xff;
|
||||
count_buf[3] = count & 0xff;
|
||||
if (wpa_hmac_sha1_vector((u8 *) passphrase, passphrase_len, 2, addr, len,
|
||||
tmp))
|
||||
return -1;
|
||||
os_memcpy(digest, tmp, SHA1_MAC_LEN);
|
||||
|
||||
for (i = 1; i < iterations; i++) {
|
||||
if (wpa_hmac_sha1((u8 *) passphrase, passphrase_len, tmp,
|
||||
SHA1_MAC_LEN, tmp2))
|
||||
return -1;
|
||||
os_memcpy(tmp, tmp2, SHA1_MAC_LEN);
|
||||
for (j = 0; j < SHA1_MAC_LEN; j++)
|
||||
digest[j] ^= tmp2[j];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pbkdf2_sha1 - 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.
|
||||
*/
|
||||
int
|
||||
wpa_pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
|
||||
int iterations, u8 *buf, size_t buflen)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
unsigned char *pos = buf;
|
||||
size_t left = buflen, plen;
|
||||
unsigned char digest[SHA1_MAC_LEN];
|
||||
|
||||
while (left > 0) {
|
||||
count++;
|
||||
if (wpa_pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations,
|
||||
count, digest))
|
||||
return -1;
|
||||
plen = left > SHA1_MAC_LEN ? SHA1_MAC_LEN : left;
|
||||
os_memcpy(pos, digest, plen);
|
||||
pos += plen;
|
||||
left -= plen;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
165
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha1.c
vendored
Normal file
165
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha1.c
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* SHA1 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/sha1.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
||||
/**
|
||||
* hmac_sha1_vector - 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
|
||||
*/
|
||||
int
|
||||
wpa_hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
|
||||
unsigned char tk[20];
|
||||
const u8 *_addr[6];
|
||||
size_t _len[6], i;
|
||||
|
||||
if (num_elem > 5) {
|
||||
/*
|
||||
* Fixed limit on the number of fragments to avoid having to
|
||||
* allocate memory (which could fail).
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key = SHA1(key) */
|
||||
if (key_len > 64) {
|
||||
if (wpa_sha1_vector(1, &key, &key_len, tk))
|
||||
return -1;
|
||||
key = tk;
|
||||
key_len = 20;
|
||||
}
|
||||
|
||||
/* the HMAC_SHA1 transform looks like:
|
||||
*
|
||||
* SHA1(K XOR opad, SHA1(K XOR ipad, text))
|
||||
*
|
||||
* where K is an n byte key
|
||||
* ipad is the byte 0x36 repeated 64 times
|
||||
* opad is the byte 0x5c repeated 64 times
|
||||
* and text is the data being protected */
|
||||
|
||||
/* start out by storing key in ipad */
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with ipad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
|
||||
/* perform inner SHA1 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i + 1] = addr[i];
|
||||
_len[i + 1] = len[i];
|
||||
}
|
||||
if (wpa_sha1_vector(1 + num_elem, _addr, _len, mac))
|
||||
return -1;
|
||||
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with opad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
|
||||
/* perform outer SHA1 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
_addr[1] = mac;
|
||||
_len[1] = SHA1_MAC_LEN;
|
||||
return wpa_sha1_vector(2, _addr, _len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hmac_sha1 - 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
|
||||
*/
|
||||
int
|
||||
wpa_hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
|
||||
u8 *mac)
|
||||
{
|
||||
return wpa_hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
|
||||
}
|
||||
|
||||
/**
|
||||
* sha1_prf - 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).
|
||||
*/
|
||||
int
|
||||
wpa_sha1_prf(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
|
||||
{
|
||||
u8 counter = 0;
|
||||
size_t pos, plen;
|
||||
u8 hash[SHA1_MAC_LEN];
|
||||
size_t label_len = os_strlen(label) + 1;
|
||||
const unsigned char *addr[3];
|
||||
size_t len[3];
|
||||
|
||||
addr[0] = (u8 *) label;
|
||||
len[0] = label_len;
|
||||
addr[1] = data;
|
||||
len[1] = data_len;
|
||||
addr[2] = &counter;
|
||||
len[2] = 1;
|
||||
|
||||
pos = 0;
|
||||
while (pos < buf_len) {
|
||||
plen = buf_len - pos;
|
||||
if (plen >= SHA1_MAC_LEN) {
|
||||
if (wpa_hmac_sha1_vector(key, key_len, 3, addr, len,
|
||||
&buf[pos]))
|
||||
return -1;
|
||||
pos += SHA1_MAC_LEN;
|
||||
} else {
|
||||
if (wpa_hmac_sha1_vector(key, key_len, 3, addr, len,
|
||||
hash))
|
||||
return -1;
|
||||
os_memcpy(&buf[pos], hash, plen);
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
249
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha256-internal.c
vendored
Normal file
249
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha256-internal.c
vendored
Normal file
@ -0,0 +1,249 @@
|
||||
/*
|
||||
* SHA-256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/sha256.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
#define SHA256_BLOCK_SIZE 64
|
||||
|
||||
struct sha256_state {
|
||||
u64 length;
|
||||
u32 state[8], curlen;
|
||||
u8 buf[SHA256_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
static void wpa_sha256_init(struct sha256_state *md);
|
||||
static int wpa_sha256_process(struct sha256_state *md, const unsigned char *in,
|
||||
unsigned long inlen);
|
||||
static int wpa_sha256_done(struct sha256_state *md, unsigned char *out);
|
||||
|
||||
|
||||
/**
|
||||
* sha256_vector - SHA256 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 of failure
|
||||
*/
|
||||
int
|
||||
wpa_sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *mac)
|
||||
{
|
||||
struct sha256_state ctx;
|
||||
size_t i;
|
||||
|
||||
wpa_sha256_init(&ctx);
|
||||
for (i = 0; i < num_elem; i++)
|
||||
if (wpa_sha256_process(&ctx, addr[i], len[i]))
|
||||
return -1;
|
||||
if (wpa_sha256_done(&ctx, mac))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===== start - public domain SHA256 implementation ===== */
|
||||
|
||||
/* This is based on SHA256 implementation in LibTomCrypt that was released into
|
||||
* public domain by Tom St Denis. */
|
||||
|
||||
/* the K array */
|
||||
static const unsigned long K[64] = {
|
||||
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
|
||||
0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
|
||||
0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
|
||||
0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
|
||||
0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
|
||||
0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
|
||||
0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
|
||||
0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
|
||||
0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
|
||||
0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
|
||||
0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
|
||||
0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
|
||||
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
|
||||
};
|
||||
|
||||
|
||||
/* Various logical functions */
|
||||
#define RORc(x, y) \
|
||||
( ((((unsigned long) (x) & 0xFFFFFFFFUL) >> (unsigned long) ((y) & 31)) | \
|
||||
((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)
|
||||
#define Ch(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define Maj(x,y,z) (((x | y) & z) | (x & y))
|
||||
#define S(x, n) RORc((x), (n))
|
||||
#define R(x, n) (((x)&0xFFFFFFFFUL)>>(n))
|
||||
#define Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
|
||||
#define Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
|
||||
#define Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
|
||||
#define Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
/* compress 512-bits */
|
||||
static int
|
||||
wpa_sha256_compress(struct sha256_state *md, unsigned char *buf)
|
||||
{
|
||||
u32 S[8], W[64], t0, t1;
|
||||
u32 t;
|
||||
int i;
|
||||
|
||||
/* copy state into S */
|
||||
for (i = 0; i < 8; i++) {
|
||||
S[i] = md->state[i];
|
||||
}
|
||||
|
||||
/* copy the state into 512-bits into W[0..15] */
|
||||
for (i = 0; i < 16; i++)
|
||||
W[i] = WPA_GET_BE32(buf + (4 * i));
|
||||
|
||||
/* fill W[16..63] */
|
||||
for (i = 16; i < 64; i++) {
|
||||
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) +
|
||||
W[i - 16];
|
||||
}
|
||||
|
||||
/* Compress */
|
||||
#define RND(a,b,c,d,e,f,g,h,i) \
|
||||
t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
|
||||
t1 = Sigma0(a) + Maj(a, b, c); \
|
||||
d += t0; \
|
||||
h = t0 + t1;
|
||||
|
||||
for (i = 0; i < 64; ++i) {
|
||||
RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
|
||||
t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
|
||||
S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
|
||||
}
|
||||
|
||||
/* feedback */
|
||||
for (i = 0; i < 8; i++) {
|
||||
md->state[i] = md->state[i] + S[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Initialize the hash state */
|
||||
static void
|
||||
wpa_sha256_init(struct sha256_state *md)
|
||||
{
|
||||
md->curlen = 0;
|
||||
md->length = 0;
|
||||
md->state[0] = 0x6A09E667UL;
|
||||
md->state[1] = 0xBB67AE85UL;
|
||||
md->state[2] = 0x3C6EF372UL;
|
||||
md->state[3] = 0xA54FF53AUL;
|
||||
md->state[4] = 0x510E527FUL;
|
||||
md->state[5] = 0x9B05688CUL;
|
||||
md->state[6] = 0x1F83D9ABUL;
|
||||
md->state[7] = 0x5BE0CD19UL;
|
||||
}
|
||||
|
||||
/**
|
||||
Process a block of memory though the hash
|
||||
@param md The hash state
|
||||
@param in The data to hash
|
||||
@param inlen The length of the data (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
static int
|
||||
wpa_sha256_process(struct sha256_state *md, const unsigned char *in,
|
||||
unsigned long inlen)
|
||||
{
|
||||
unsigned long n;
|
||||
|
||||
if (md->curlen >= sizeof(md->buf))
|
||||
return -1;
|
||||
|
||||
while (inlen > 0) {
|
||||
if (md->curlen == 0 && inlen >= SHA256_BLOCK_SIZE) {
|
||||
if (wpa_sha256_compress(md, (unsigned char *) in) < 0)
|
||||
return -1;
|
||||
md->length += SHA256_BLOCK_SIZE * 8;
|
||||
in += SHA256_BLOCK_SIZE;
|
||||
inlen -= SHA256_BLOCK_SIZE;
|
||||
} else {
|
||||
n = MIN(inlen, (SHA256_BLOCK_SIZE - md->curlen));
|
||||
os_memcpy(md->buf + md->curlen, in, n);
|
||||
md->curlen += n;
|
||||
in += n;
|
||||
inlen -= n;
|
||||
if (md->curlen == SHA256_BLOCK_SIZE) {
|
||||
if (wpa_sha256_compress(md, md->buf) < 0)
|
||||
return -1;
|
||||
md->length += 8 * SHA256_BLOCK_SIZE;
|
||||
md->curlen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Terminate the hash to get the digest
|
||||
@param md The hash state
|
||||
@param out [out] The destination of the hash (32 bytes)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
static int
|
||||
wpa_sha256_done(struct sha256_state *md, unsigned char *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (md->curlen >= sizeof(md->buf))
|
||||
return -1;
|
||||
|
||||
/* increase the length of the message */
|
||||
md->length += md->curlen * 8;
|
||||
|
||||
/* append the '1' bit */
|
||||
md->buf[md->curlen++] = (unsigned char) 0x80;
|
||||
|
||||
/* if the length is currently above 56 bytes we append zeros
|
||||
* then compress. Then we can fall back to padding zeros and length
|
||||
* encoding like normal.
|
||||
*/
|
||||
if (md->curlen > 56) {
|
||||
while (md->curlen < SHA256_BLOCK_SIZE) {
|
||||
md->buf[md->curlen++] = (unsigned char) 0;
|
||||
}
|
||||
wpa_sha256_compress(md, md->buf);
|
||||
md->curlen = 0;
|
||||
}
|
||||
|
||||
/* pad up to 56 bytes of zeroes */
|
||||
while (md->curlen < 56) {
|
||||
md->buf[md->curlen++] = (unsigned char) 0;
|
||||
}
|
||||
|
||||
/* store length */
|
||||
WPA_PUT_BE64(md->buf + 56, md->length);
|
||||
wpa_sha256_compress(md, md->buf);
|
||||
|
||||
/* copy output */
|
||||
for (i = 0; i < 8; i++)
|
||||
WPA_PUT_BE32(out + (4 * i), md->state[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ===== end - public domain SHA256 implementation ===== */
|
160
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha256.c
vendored
Normal file
160
cpu/esp8266/vendor/esp-idf/wpa_supplicant/src/crypto/sha256.c
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* SHA-256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/sha256.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
||||
/**
|
||||
* hmac_sha256_vector - HMAC-SHA256 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 (32 bytes)
|
||||
*/
|
||||
void
|
||||
wpa_hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
|
||||
unsigned char tk[32];
|
||||
const u8 *_addr[6];
|
||||
size_t _len[6], i;
|
||||
|
||||
if (num_elem > 5) {
|
||||
/*
|
||||
* Fixed limit on the number of fragments to avoid having to
|
||||
* allocate memory (which could fail).
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key = SHA256(key) */
|
||||
if (key_len > 64) {
|
||||
wpa_sha256_vector(1, &key, &key_len, tk);
|
||||
key = tk;
|
||||
key_len = 32;
|
||||
}
|
||||
|
||||
/* the HMAC_SHA256 transform looks like:
|
||||
*
|
||||
* SHA256(K XOR opad, SHA256(K XOR ipad, text))
|
||||
*
|
||||
* where K is an n byte key
|
||||
* ipad is the byte 0x36 repeated 64 times
|
||||
* opad is the byte 0x5c repeated 64 times
|
||||
* and text is the data being protected */
|
||||
|
||||
/* start out by storing key in ipad */
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with ipad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
|
||||
/* perform inner SHA256 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i + 1] = addr[i];
|
||||
_len[i + 1] = len[i];
|
||||
}
|
||||
wpa_sha256_vector(1 + num_elem, _addr, _len, mac);
|
||||
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with opad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
|
||||
/* perform outer SHA256 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
_addr[1] = mac;
|
||||
_len[1] = SHA256_MAC_LEN;
|
||||
wpa_sha256_vector(2, _addr, _len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hmac_sha256 - HMAC-SHA256 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)
|
||||
*/
|
||||
void
|
||||
wpa_hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
|
||||
size_t data_len, u8 *mac)
|
||||
{
|
||||
wpa_hmac_sha256_vector(key, key_len, 1, &data, &data_len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sha256_prf - SHA256-based Pseudo-Random Function (IEEE 802.11r, 8.5.1.5.2)
|
||||
* @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
|
||||
*
|
||||
* This function is used to derive new, cryptographically separate keys from a
|
||||
* given key.
|
||||
*/
|
||||
void
|
||||
wpa_sha256_prf(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
|
||||
{
|
||||
u16 counter = 1;
|
||||
size_t pos, plen;
|
||||
u8 hash[SHA256_MAC_LEN];
|
||||
const u8 *addr[4];
|
||||
size_t len[4];
|
||||
u8 counter_le[2], length_le[2];
|
||||
|
||||
addr[0] = counter_le;
|
||||
len[0] = 2;
|
||||
addr[1] = (u8 *) label;
|
||||
len[1] = os_strlen(label);
|
||||
addr[2] = data;
|
||||
len[2] = data_len;
|
||||
addr[3] = length_le;
|
||||
len[3] = sizeof(length_le);
|
||||
|
||||
WPA_PUT_LE16(length_le, buf_len * 8);
|
||||
pos = 0;
|
||||
while (pos < buf_len) {
|
||||
plen = buf_len - pos;
|
||||
WPA_PUT_LE16(counter_le, counter);
|
||||
if (plen >= SHA256_MAC_LEN) {
|
||||
wpa_hmac_sha256_vector(key, key_len, 4, addr, len,
|
||||
&buf[pos]);
|
||||
pos += SHA256_MAC_LEN;
|
||||
} else {
|
||||
wpa_hmac_sha256_vector(key, key_len, 4, addr, len, hash);
|
||||
os_memcpy(&buf[pos], hash, plen);
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user