chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/* Common utilities for socket address input interface:
|
||||
The API get_addr_from_stdin() is mainly used by socket client examples which read IP address from stdin (if configured).
|
||||
This option is typically used in the CI, but could be enabled in the project configuration.
|
||||
In that case this component is used to receive a string that is evaluated and processed to output
|
||||
socket structures to open a connectio
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Read and evaluate IP address from stdin
|
||||
*
|
||||
* This API reads stdin and parses the input address using getaddrinfo()
|
||||
* to fill in struct sockaddr_storage (for both IPv4 and IPv6) used to open
|
||||
* a socket. IP protocol is guessed from the IP address string.
|
||||
*
|
||||
* @param[in] port port number of expected connection
|
||||
* @param[in] sock_type expected protocol: SOCK_STREAM or SOCK_DGRAM
|
||||
* @param[out] ip_protocol resultant IP protocol: IPPROTO_IP or IPPROTO_IP6
|
||||
* @param[out] addr_family resultant address family: AF_INET or AF_INET6
|
||||
* @param[out] dest_addr sockaddr_storage structure (for both IPv4 and IPv6)
|
||||
* @return ESP_OK on success, ESP_FAIL otherwise
|
||||
*/
|
||||
esp_err_t get_addr_from_stdin(int port, int sock_type,
|
||||
int *ip_protocol,
|
||||
int *addr_family,
|
||||
struct sockaddr_storage *dest_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
/* Private Functions of protocol example common */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_CONNECT_IPV6
|
||||
#define MAX_IP6_ADDRS_PER_NETIF (5)
|
||||
|
||||
#if defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_LOCAL_LINK)
|
||||
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_LINK_LOCAL
|
||||
#elif defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_GLOBAL)
|
||||
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_GLOBAL
|
||||
#elif defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_SITE_LOCAL)
|
||||
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_SITE_LOCAL
|
||||
#elif defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_UNIQUE_LOCAL)
|
||||
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_UNIQUE_LOCAL
|
||||
#endif // if-elif CONFIG_EXAMPLE_CONNECT_IPV6_PREF_...
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_EXAMPLE_CONNECT_IPV6
|
||||
extern const char *example_ipv6_addr_types_to_str[6];
|
||||
#endif
|
||||
|
||||
void example_wifi_start(void);
|
||||
void example_wifi_stop(void);
|
||||
esp_err_t example_wifi_sta_do_connect(wifi_config_t wifi_config, bool wait);
|
||||
esp_err_t example_wifi_sta_do_disconnect(void);
|
||||
bool example_is_our_netif(const char *prefix, esp_netif_t *netif);
|
||||
void example_print_all_netif_ips(const char *prefix);
|
||||
void example_wifi_shutdown(void);
|
||||
esp_err_t example_wifi_connect(void);
|
||||
void example_ethernet_shutdown(void);
|
||||
esp_err_t example_ethernet_connect(void);
|
||||
void example_thread_shutdown(void);
|
||||
esp_err_t example_thread_connect(void);
|
||||
esp_err_t example_ppp_connect(void);
|
||||
void example_ppp_start(void);
|
||||
void example_ppp_shutdown(void);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/* Common functions for protocol examples, to establish Wi-Fi or Ethernet connection.
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#if !CONFIG_IDF_TARGET_LINUX
|
||||
#include "esp_netif.h"
|
||||
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !CONFIG_IDF_TARGET_LINUX
|
||||
#if CONFIG_EXAMPLE_CONNECT_WIFI
|
||||
#define EXAMPLE_NETIF_DESC_STA "example_netif_sta"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||
#define EXAMPLE_NETIF_DESC_ETH "example_netif_eth"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_CONNECT_THREAD
|
||||
#define EXAMPLE_NETIF_DESC_THREAD "example_netif_thread"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_CONNECT_PPP
|
||||
#define EXAMPLE_NETIF_DESC_PPP "example_netif_ppp"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_WIFI_SCAN_METHOD_FAST
|
||||
#define EXAMPLE_WIFI_SCAN_METHOD WIFI_FAST_SCAN
|
||||
#elif CONFIG_EXAMPLE_WIFI_SCAN_METHOD_ALL_CHANNEL
|
||||
#define EXAMPLE_WIFI_SCAN_METHOD WIFI_ALL_CHANNEL_SCAN
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_WIFI_CONNECT_AP_BY_SIGNAL
|
||||
#define EXAMPLE_WIFI_CONNECT_AP_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
|
||||
#elif CONFIG_EXAMPLE_WIFI_CONNECT_AP_BY_SECURITY
|
||||
#define EXAMPLE_WIFI_CONNECT_AP_SORT_METHOD WIFI_CONNECT_AP_BY_SECURITY
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_WIFI_AUTH_OPEN
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WEP
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA_PSK
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA2_PSK
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA2_ENTERPRISE
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_ENTERPRISE
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA3_PSK
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_EXAMPLE_WIFI_AUTH_WAPI_PSK
|
||||
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
|
||||
/* Example default interface, prefer the ethernet one if running in example-test (CI) configuration */
|
||||
#if CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||
#define EXAMPLE_INTERFACE get_example_netif_from_desc(EXAMPLE_NETIF_DESC_ETH)
|
||||
#define get_example_netif() get_example_netif_from_desc(EXAMPLE_NETIF_DESC_ETH)
|
||||
#elif CONFIG_EXAMPLE_CONNECT_WIFI
|
||||
#define EXAMPLE_INTERFACE get_example_netif_from_desc(EXAMPLE_NETIF_DESC_STA)
|
||||
#define get_example_netif() get_example_netif_from_desc(EXAMPLE_NETIF_DESC_STA)
|
||||
#elif CONFIG_EXAMPLE_CONNECT_THREAD
|
||||
#define EXAMPLE_INTERFACE get_example_netif_from_desc(EXAMPLE_NETIF_DESC_THREAD)
|
||||
#define get_example_netif() get_example_netif_from_desc(EXAMPLE_NETIF_DESC_THREAD)
|
||||
#elif CONFIG_EXAMPLE_CONNECT_PPP
|
||||
#define EXAMPLE_INTERFACE get_example_netif_from_desc(EXAMPLE_NETIF_DESC_PPP)
|
||||
#define get_example_netif() get_example_netif_from_desc(EXAMPLE_NETIF_DESC_PPP)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Configure Wi-Fi or Ethernet, connect, wait for IP
|
||||
*
|
||||
* This all-in-one helper function is used in protocols examples to
|
||||
* reduce the amount of boilerplate in the example.
|
||||
*
|
||||
* It is not intended to be used in real world applications.
|
||||
* See examples under examples/wifi/getting_started/ and examples/ethernet/
|
||||
* for more complete Wi-Fi or Ethernet initialization code.
|
||||
*
|
||||
* Read "Establishing Wi-Fi or Ethernet Connection" section in
|
||||
* examples/protocols/README.md for more information about this function.
|
||||
*
|
||||
* @return ESP_OK on successful connection
|
||||
*/
|
||||
esp_err_t example_connect(void);
|
||||
|
||||
/**
|
||||
* Counterpart to example_connect, de-initializes Wi-Fi or Ethernet
|
||||
*/
|
||||
esp_err_t example_disconnect(void);
|
||||
|
||||
/**
|
||||
* @brief Configure stdin and stdout to use blocking I/O
|
||||
*
|
||||
* This helper function is used in some examples. It wraps installing the
|
||||
* UART driver and configuring VFS layer to use UART driver for console I/O.
|
||||
*/
|
||||
esp_err_t example_configure_stdin_stdout(void);
|
||||
|
||||
/**
|
||||
* @brief Returns esp-netif pointer created by example_connect() described by
|
||||
* the supplied desc field
|
||||
*
|
||||
* @param desc Textual interface of created network interface, for example "sta"
|
||||
* indicate default WiFi station, "eth" default Ethernet interface.
|
||||
*
|
||||
*/
|
||||
esp_netif_t *get_example_netif_from_desc(const char *desc);
|
||||
|
||||
#if CONFIG_EXAMPLE_PROVIDE_WIFI_CONSOLE_CMD
|
||||
/**
|
||||
* @brief Register wifi connect commands
|
||||
*
|
||||
* Provide a simple wifi_connect command in esp_console.
|
||||
* This function can be used after esp_console is initialized.
|
||||
*/
|
||||
void example_register_wifi_connect_commands(void);
|
||||
#endif
|
||||
|
||||
#else
|
||||
static inline esp_err_t example_connect(void) {return ESP_OK;}
|
||||
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Thread configurations for protocol examples
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <sdkconfig.h>
|
||||
|
||||
#include <esp_openthread_types.h>
|
||||
|
||||
#ifdef CONFIG_OPENTHREAD_RADIO_NATIVE
|
||||
#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \
|
||||
{ \
|
||||
.radio_mode = RADIO_MODE_NATIVE, \
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_OPENTHREAD_RADIO_SPINEL_UART)
|
||||
#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \
|
||||
{ \
|
||||
.radio_mode = RADIO_MODE_UART_RCP, \
|
||||
.radio_uart_config = \
|
||||
{ \
|
||||
.port = CONFIG_EXAMPLE_THREAD_UART_PORT, \
|
||||
.uart_config = \
|
||||
{ \
|
||||
.baud_rate = CONFIG_EXAMPLE_THREAD_UART_BAUD, \
|
||||
.data_bits = UART_DATA_8_BITS, \
|
||||
.parity = UART_PARITY_DISABLE, \
|
||||
.stop_bits = UART_STOP_BITS_1, \
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \
|
||||
.rx_flow_ctrl_thresh = 0, \
|
||||
.source_clk = UART_SCLK_DEFAULT, \
|
||||
}, \
|
||||
.rx_pin = CONFIG_EXAMPLE_THREAD_UART_RX_PIN, \
|
||||
.tx_pin = CONFIG_EXAMPLE_THREAD_UART_TX_PIN, \
|
||||
}, \
|
||||
}
|
||||
#elif defined(CONFIG_OPENTHREAD_RADIO_SPINEL_SPI)
|
||||
#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \
|
||||
{ \
|
||||
.radio_mode = RADIO_MODE_SPI_RCP, \
|
||||
.radio_spi_config = \
|
||||
{ \
|
||||
.host_device = SPI2_HOST, \
|
||||
.dma_channel = 2, \
|
||||
.spi_interface = \
|
||||
{ \
|
||||
.mosi_io_num = CONFIG_EXAMPLE_THREAD_SPI_MOSI_PIN, \
|
||||
.miso_io_num = CONFIG_EXAMPLE_THREAD_SPI_MISO_PIN, \
|
||||
.sclk_io_num = CONFIG_EXAMPLE_THREAD_SPI_SCLK_PIN, \
|
||||
.quadwp_io_num = -1, \
|
||||
.quadhd_io_num = -1, \
|
||||
}, \
|
||||
.spi_device = \
|
||||
{ \
|
||||
.cs_ena_pretrans = 2, \
|
||||
.input_delay_ns = 100, \
|
||||
.mode = 0, \
|
||||
.clock_speed_hz = 2500 * 1000, \
|
||||
.spics_io_num = CONFIG_EXAMPLE_THREAD_SPI_CS_PIN, \
|
||||
.queue_size = 5, \
|
||||
}, \
|
||||
.intr_pin = CONFIG_EXAMPLE_THREAD_SPI_INTR_PIN, \
|
||||
}, \
|
||||
}
|
||||
#else
|
||||
#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \
|
||||
{ \
|
||||
.radio_mode = RADIO_MODE_TREL, \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_OPENTHREAD_CONSOLE_TYPE_UART
|
||||
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
|
||||
{ \
|
||||
.host_connection_mode = HOST_CONNECTION_MODE_CLI_UART, \
|
||||
.host_uart_config = \
|
||||
{ \
|
||||
.port = 0, \
|
||||
.uart_config = \
|
||||
{ \
|
||||
.baud_rate = 115200, \
|
||||
.data_bits = UART_DATA_8_BITS, \
|
||||
.parity = UART_PARITY_DISABLE, \
|
||||
.stop_bits = UART_STOP_BITS_1, \
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \
|
||||
.rx_flow_ctrl_thresh = 0, \
|
||||
.source_clk = UART_SCLK_DEFAULT, \
|
||||
}, \
|
||||
.rx_pin = UART_PIN_NO_CHANGE, \
|
||||
.tx_pin = UART_PIN_NO_CHANGE, \
|
||||
}, \
|
||||
}
|
||||
#elif CONFIG_OPENTHREAD_CONSOLE_TYPE_USB_SERIAL_JTAG
|
||||
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
|
||||
{ \
|
||||
.host_connection_mode = HOST_CONNECTION_MODE_CLI_USB, \
|
||||
.host_usb_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(), \
|
||||
}
|
||||
#else
|
||||
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
|
||||
{ \
|
||||
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \
|
||||
{ \
|
||||
.storage_partition_name = "nvs", \
|
||||
.netif_queue_size = 10, \
|
||||
.task_queue_size = 10, \
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Utility functions for protocol examples
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Encode an URI
|
||||
*
|
||||
* @param dest a destination memory location
|
||||
* @param src the source string
|
||||
* @param len the length of the source string
|
||||
* @return uint32_t the count of escaped characters
|
||||
*
|
||||
* @note Please allocate the destination buffer keeping in mind that encoding a
|
||||
* special character will take up 3 bytes (for '%' and two hex digits).
|
||||
* In the worst-case scenario, the destination buffer will have to be 3 times
|
||||
* that of the source string.
|
||||
*/
|
||||
uint32_t example_uri_encode(char *dest, const char *src, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Decode an URI
|
||||
*
|
||||
* @param dest a destination memory location
|
||||
* @param src the source string
|
||||
* @param len the length of the source string
|
||||
*
|
||||
* @note Please allocate the destination buffer keeping in mind that a decoded
|
||||
* special character will take up 2 less bytes than its encoded form.
|
||||
* In the worst-case scenario, the destination buffer will have to be
|
||||
* the same size that of the source string.
|
||||
*/
|
||||
void example_uri_decode(char *dest, const char *src, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user