diff --git a/components/esp_netif/include/esp_netif.h b/components/esp_netif/include/esp_netif.h index 20f468739b..91c7356368 100644 --- a/components/esp_netif/include/esp_netif.h +++ b/components/esp_netif/include/esp_netif.h @@ -571,9 +571,10 @@ esp_err_t esp_netif_dhcps_stop(esp_netif_t *esp_netif); * * If DHCP server is enabled, the Main DNS Server setting is used by the DHCP server to provide a DNS Server option * to DHCP clients (Wi-Fi stations). - * - The default Main DNS server is typically the IP of the Wi-Fi AP interface itself. + * - The default Main DNS server is typically the IP of the DHCP server itself. * - This function can override it by setting server type ESP_NETIF_DNS_MAIN. - * - Other DNS Server types are not supported for the Wi-Fi AP interface. + * - Other DNS Server types are not supported for the DHCP server. + * - To propagate the DNS info to client, please stop the DHCP server before using this API. * * @param[in] esp_netif Handle to esp-netif instance * @param[in] type Type of DNS Server to set: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld index 461f70694d..390cf6a06c 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld @@ -10,7 +10,7 @@ ppMapTxQueue = 0x400016d8; rcGetSched = 0x40001764; wDevCheckBlockError = 0x400017b4; ppProcTxDone = 0x40001804; -sta_input = rom_sta_input; +/*sta_input = rom_sta_input;*/ /*************************************** Group rom_phy diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index 74bb30a125..5a77d2af02 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -1550,7 +1550,7 @@ pm_on_data_rx = 0x40001680; pm_on_tbtt = 0x40001684; pm_parse_beacon = 0x40001688; pm_process_tim = 0x4000168c; -pm_rx_beacon_process = 0x40001690; +/*pm_rx_beacon_process = 0x40001690;*/ pm_rx_data_process = 0x40001694; /*pm_sleep = 0x40001698;*/ pm_sleep_for = 0x4000169c; diff --git a/components/esp_wifi/include/esp_now.h b/components/esp_wifi/include/esp_now.h index de41a87936..d7ffe2bf93 100644 --- a/components/esp_wifi/include/esp_now.h +++ b/components/esp_wifi/include/esp_now.h @@ -1,16 +1,8 @@ -// 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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef __ESP_NOW_H__ #define __ESP_NOW_H__ @@ -237,6 +229,20 @@ esp_err_t esp_now_del_peer(const uint8_t *peer_addr); */ esp_err_t esp_now_mod_peer(const esp_now_peer_info_t *peer); +/** + * @brief Config ESPNOW rate of specified interface + * + * @attention 1. This API should be called after esp_wifi_start(). + * + * @param ifx Interface to be configured. + * @param rate Phy rate to be configured. + * + * @return + * - ESP_OK: succeed + * - others: failed + */ +esp_err_t esp_wifi_config_espnow_rate(wifi_interface_t ifx, wifi_phy_rate_t rate); + /** * @brief Get a peer whose MAC address matches peer_addr from peer list * diff --git a/components/esp_wifi/include/esp_private/wifi.h b/components/esp_wifi/include/esp_private/wifi.h index 957f68791b..a2c763260e 100644 --- a/components/esp_wifi/include/esp_private/wifi.h +++ b/components/esp_wifi/include/esp_private/wifi.h @@ -251,6 +251,7 @@ esp_err_t esp_wifi_internal_set_sta_ip(void); * * @attention 1. If fixed rate is enabled, both management and data frame are transmitted with fixed rate * @attention 2. Make sure that the receiver is able to receive the frame with the fixed rate if you want the frame to be received + * @attention 3. Not support to set fix rate for espnow and 80211_tx * * @param ifx : wifi interface * @param en : false - disable, true - enable diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index ca926bfd00..09b4c65436 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -1218,20 +1218,6 @@ esp_err_t esp_wifi_ftm_resp_set_offset(int16_t offset_cm); */ esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable); -/** - * @brief Config ESPNOW rate of specified interface - * - * @attention 1. This API should be called after esp_wifi_init() and before esp_wifi_start(). - * - * @param ifx Interface to be configured. - * @param rate Phy rate to be configured. - * - * @return - * - ESP_OK: succeed - * - others: failed - */ -esp_err_t esp_wifi_config_espnow_rate(wifi_interface_t ifx, wifi_phy_rate_t rate); - /** * @brief Set interval for station to wake up periodically at disconnected. * diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index 199de43766..9adf79d561 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -345,7 +345,7 @@ typedef struct { unsigned fec_coding:1; /**< Flag is set for 11n packets which are LDPC */ unsigned sgi:1; /**< Short Guide Interval(SGI). 0: Long GI; 1: Short GI */ #if CONFIG_IDF_TARGET_ESP32 - signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ + signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: dBm*/ #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 unsigned :8; /**< reserved */ #endif @@ -358,14 +358,14 @@ typedef struct { #if CONFIG_IDF_TARGET_ESP32S2 unsigned :32; /**< reserved */ #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 - signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ + signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: dBm*/ unsigned :24; /**< reserved */ unsigned :32; /**< reserved */ #endif unsigned :31; /**< reserved */ unsigned ant:1; /**< antenna number from which this packet is received. 0: WiFi antenna 0; 1: WiFi antenna 1 */ #if CONFIG_IDF_TARGET_ESP32S2 - signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ + signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: dBm*/ unsigned :24; /**< reserved */ #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 unsigned :32; /**< reserved */ diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index ef6c4a7cb1..c9f08e68e3 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit ef6c4a7cb1702c8568eb952bfdf33eace1ba7bf6 +Subproject commit c9f08e68e38e9412f3f943778af1ba49bb27067d diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index e10947cdbd..1ad7a8b037 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -877,6 +877,13 @@ menu "LWIP" bool "Enable LWIP Debug" default n + config LWIP_DEBUG_ESP_LOG + bool "Route LWIP debugs through ESP_LOG interface" + depends on LWIP_DEBUG + default n + help + Enabling this option routes all enabled LWIP debugs through ESP_LOGD. + config LWIP_NETIF_DEBUG bool "Enable netif debug messages" depends on LWIP_DEBUG diff --git a/components/lwip/apps/ping/esp_ping.c b/components/lwip/apps/ping/esp_ping.c index ece50cff14..7983d6fed1 100644 --- a/components/lwip/apps/ping/esp_ping.c +++ b/components/lwip/apps/ping/esp_ping.c @@ -25,6 +25,7 @@ typedef struct _ping_option { size_t ping_data_len; uint16_t ping_id; u8_t ping_tos; + u8_t ping_ttl; esp_ping_found_fn ping_res_fn; esp_ping_found ping_res; void *ping_reserve; diff --git a/components/lwip/apps/ping/ping_sock.c b/components/lwip/apps/ping/ping_sock.c index c082b8cff3..2afca9939e 100644 --- a/components/lwip/apps/ping/ping_sock.c +++ b/components/lwip/apps/ping/ping_sock.c @@ -67,6 +67,7 @@ typedef struct { uint32_t elapsed_time_ms; uint32_t total_time_ms; uint8_t ttl; + uint8_t tos; uint32_t flags; void (*on_ping_success)(esp_ping_handle_t hdl, void *args); void (*on_ping_timeout)(esp_ping_handle_t hdl, void *args); @@ -131,6 +132,7 @@ static int esp_ping_receive(esp_ping_t *ep) if ((iecho->id == ep->packet_hdr->id) && (iecho->seqno == ep->packet_hdr->seqno)) { ep->received++; ep->ttl = iphdr->_ttl; + ep->tos = iphdr->_tos; ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP return len; } @@ -289,6 +291,9 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c /* set tos */ setsockopt(ep->sock, IPPROTO_IP, IP_TOS, &config->tos, sizeof(config->tos)); + /* set ttl */ + setsockopt(ep->sock, IPPROTO_IP, IP_TTL, &config->ttl, sizeof(config->ttl)); + /* set socket address */ if (IP_IS_V4(&config->target_addr)) { struct sockaddr_in *to4 = (struct sockaddr_in *)&ep->target_addr; @@ -371,6 +376,10 @@ esp_err_t esp_ping_get_profile(esp_ping_handle_t hdl, esp_ping_profile_t profile from = &ep->packet_hdr->seqno; copy_size = sizeof(ep->packet_hdr->seqno); break; + case ESP_PING_PROF_TOS: + from = &ep->tos; + copy_size = sizeof(ep->tos); + break; case ESP_PING_PROF_TTL: from = &ep->ttl; copy_size = sizeof(ep->ttl); diff --git a/components/lwip/include/apps/ping/ping_sock.h b/components/lwip/include/apps/ping/ping_sock.h index 57938480d5..fb946f7e16 100644 --- a/components/lwip/include/apps/ping/ping_sock.h +++ b/components/lwip/include/apps/ping/ping_sock.h @@ -67,7 +67,8 @@ typedef struct { uint32_t interval_ms; /*!< Milliseconds between each ping procedure */ uint32_t timeout_ms; /*!< Timeout value (in milliseconds) of each ping procedure */ uint32_t data_size; /*!< Size of the data next to ICMP packet header */ - uint8_t tos; /*!< Type of Service, a field specified in the IP header */ + int tos; /*!< Type of Service, a field specified in the IP header */ + int ttl; /*!< Time to Live,a field specified in the IP header */ ip_addr_t target_addr; /*!< Target IP address, either IPv4 or IPv6 */ uint32_t task_stack_size; /*!< Stack size of internal ping task */ uint32_t task_prio; /*!< Priority of internal ping task */ @@ -85,6 +86,7 @@ typedef struct { .timeout_ms = 1000, \ .data_size = 64, \ .tos = 0, \ + .ttl = IP_DEFAULT_TTL, \ .target_addr = *(IP_ANY_TYPE), \ .task_stack_size = 2048, \ .task_prio = 2, \ @@ -99,6 +101,7 @@ typedef struct { */ typedef enum { ESP_PING_PROF_SEQNO, /*!< Sequence number of a ping procedure */ + ESP_PING_PROF_TOS, /*!< Type of service of a ping procedure */ ESP_PING_PROF_TTL, /*!< Time to live of a ping procedure */ ESP_PING_PROF_REQUEST, /*!< Number of request packets sent out */ ESP_PING_PROF_REPLY, /*!< Number of reply packets received */ diff --git a/components/lwip/port/esp32/include/arch/cc.h b/components/lwip/port/esp32/include/arch/cc.h index 78935f3b5f..b0d6adca09 100644 --- a/components/lwip/port/esp32/include/arch/cc.h +++ b/components/lwip/port/esp32/include/arch/cc.h @@ -74,7 +74,15 @@ typedef int sys_prot_t; #include +#ifdef CONFIG_LWIP_DEBUG_ESP_LOG +// lwip debugs routed to ESP_LOGD +#include "esp_log.h" +#define LWIP_ESP_LOG_FUNC(format, ...) ESP_LOG_LEVEL(ESP_LOG_DEBUG, "lwip", format, ##__VA_ARGS__) +#define LWIP_PLATFORM_DIAG(x) LWIP_ESP_LOG_FUNC x +#else +// lwip debugs routed to printf #define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0) +#endif #ifdef NDEBUG diff --git a/docs/en/api-guides/lwip.rst b/docs/en/api-guides/lwip.rst index 95791761a4..c5215a5b0e 100644 --- a/docs/en/api-guides/lwip.rst +++ b/docs/en/api-guides/lwip.rst @@ -306,6 +306,16 @@ The default lwIP implementation is to have these timers enabled all the time, ev To return to the default lwIP behaviour (always-on timers), disable :ref:`CONFIG_LWIP_TIMERS_ONDEMAND`. +Lwip timers API ++++++++++++++++ + +When users are not using WiFi, these APIs provide users with the ability to turn off LwIP timer to reduce power consumption. + +The following API functions are supported. For full details see :component_file:`lwip/lwip/src/include/lwip/timeouts.h`. + +- ``sys_timeouts_init()`` +- ``sys_timeouts_deinit()`` + Abort TCP connections when IP changes +++++++++++++++++++++++++++++++++++++ diff --git a/docs/en/api-guides/wifi.rst b/docs/en/api-guides/wifi.rst index ae3a366065..e578a772d1 100644 --- a/docs/en/api-guides/wifi.rst +++ b/docs/en/api-guides/wifi.rst @@ -205,11 +205,11 @@ IP_EVENT_GOT_IP6 ++++++++++++++++++++++++++++++++++++ This event arises when the IPV6 SLAAC support auto-configures an address for the {IDF_TARGET_NAME}, or when this address changes. The event means that everything is ready and the application can begin its tasks (e.g., creating sockets). -IP_STA_LOST_IP +IP_EVENT_STA_LOST_IP ++++++++++++++++++++++++++++++++++++ This event arises when the IPV4 address become invalid. -IP_STA_LOST_IP doesn't arise immediately after the Wi-Fi disconnects, instead it starts an IPV4 address lost timer, if the IPV4 address is got before ip lost timer expires, IP_EVENT_STA_LOST_IP doesn't happen. Otherwise, the event arises when IPV4 address lost timer expires. +IP_EVENT_STA_LOST_IP doesn't arise immediately after the Wi-Fi disconnects, instead it starts an IPV4 address lost timer, if the IPV4 address is got before ip lost timer expires, IP_EVENT_STA_LOST_IP doesn't happen. Otherwise, the event arises when IPV4 address lost timer expires. Generally the application don't need to care about this event, it is just a debug event to let the application know that the IPV4 address is lost. diff --git a/docs/en/api-reference/network/esp_now.rst b/docs/en/api-reference/network/esp_now.rst index 83df9f2cb9..966dc2cc6d 100644 --- a/docs/en/api-reference/network/esp_now.rst +++ b/docs/en/api-reference/network/esp_now.rst @@ -81,6 +81,11 @@ Receiving ESP-NOW Data Call ``esp_now_register_recv_cb`` to register receiving callback function. Call the receiving callback function when receiving ESP-NOW. The receiving callback function also runs from the Wi-Fi task. So, do not do lengthy operations in the callback function. Instead, post the necessary data to a queue and handle it from a lower priority task. +Config ESP-NOW Rate +------------------- + +Call ``esp_wifi_config_espnow_rate`` to config ESPNOW rate of specified interface. Make sure that the interface is enabled before config rate. This API should be called after ``esp_wifi_start()``. + API Reference ------------- diff --git a/docs/zh_CN/api-guides/wifi.rst b/docs/zh_CN/api-guides/wifi.rst index 7a680797da..2ff79c3af1 100644 --- a/docs/zh_CN/api-guides/wifi.rst +++ b/docs/zh_CN/api-guides/wifi.rst @@ -205,7 +205,7 @@ IP_EVENT_GOT_IP6 ++++++++++++++++++++++++++++++++++++ 当 IPV6 SLAAC 支持自动为 {IDF_TARGET_NAME} 配置一个地址,或 {IDF_TARGET_NAME} 地址发生改变时,将引发此事件。此事件意味着应用程序一切就绪,可以开始任务(如:创建套接字)。 -IP_STA_LOST_IP +IP_EVENT_STA_LOST_IP ++++++++++++++++++++++++++++++++++++ 当 IPV4 地址失效时,将引发此事件。 @@ -1294,7 +1294,7 @@ Wi-Fi 供应商 IE 配置 Wi-Fi Easy Connect™ (DPP) -------------------------- -Wi-Fi Easy Connect\ :sup:`TM`(也称为设备配置协议)是一个安全且标准化的配置协议,用于配置 Wi-Fi 设备。更多信息请参考 :doc:`esp_dpp <../api-reference/network/esp_dpp>`。 +Wi-Fi Easy Connect\ :sup:`TM` (也称为设备配置协议)是一个安全且标准化的配置协议,用于配置 Wi-Fi 设备。更多信息请参考 :doc:`esp_dpp <../api-reference/network/esp_dpp>`。 WPA2-Enterprise +++++++++++++++++++++++++++++++++ diff --git a/docs/zh_CN/api-reference/network/esp_now.rst b/docs/zh_CN/api-reference/network/esp_now.rst index 1c58c1efe7..eaebff8229 100644 --- a/docs/zh_CN/api-reference/network/esp_now.rst +++ b/docs/zh_CN/api-reference/network/esp_now.rst @@ -81,6 +81,11 @@ ESP-NOW 采用 CCMP 方法保护供应商特定动作帧的安全,具体可参 调用 ``esp_now_register_recv_cb`` 注册接收回调函数。当接收 ESP-NOW 数据时,需要调用接收回调函数。接收回调函数也在 Wi-Fi 任务任务中运行。因此,不要在回调函数中执行冗长的操作。 相反,将必要的数据发布到队列,并交给优先级较低的任务处理。 +配置 ESP-NOW 速率 +---------------------- + +调用 ``esp_wifi_config_espnow_rate`` 配置指定接口的 ESPNOW 速率。确保在配置速率之前使能接口。这个 API 应该在 ``esp_wifi_start()`` 之后调用。 + API 参考 ------------- diff --git a/examples/protocols/icmp_echo/main/echo_example_main.c b/examples/protocols/icmp_echo/main/echo_example_main.c index b4044b660e..998f975463 100644 --- a/examples/protocols/icmp_echo/main/echo_example_main.c +++ b/examples/protocols/icmp_echo/main/echo_example_main.c @@ -73,6 +73,7 @@ static struct { struct arg_int *data_size; struct arg_int *count; struct arg_int *tos; + struct arg_int *ttl; struct arg_str *host; struct arg_end *end; } ping_args; @@ -107,6 +108,10 @@ static int do_ping_cmd(int argc, char **argv) config.tos = (uint32_t)(ping_args.tos->ival[0]); } + if (ping_args.ttl->count > 0) { + config.ttl = (uint32_t)(ping_args.ttl->ival[0]); + } + // parse IP address struct sockaddr_in6 sock_addr6; ip_addr_t target_addr; @@ -156,6 +161,7 @@ static void register_ping(void) ping_args.data_size = arg_int0("s", "size", "", "Specify the number of data bytes to be sent"); ping_args.count = arg_int0("c", "count", "", "Stop after sending count packets"); ping_args.tos = arg_int0("Q", "tos", "", "Set Type of Service related bits in IP datagrams"); + ping_args.ttl = arg_int0("T", "ttl", "", "Set Time to Live related bits in IP datagrams"); ping_args.host = arg_str1(NULL, NULL, "", "Host address"); ping_args.end = arg_end(1); const esp_console_cmd_t ping_cmd = { diff --git a/examples/protocols/sockets/udp_server/README.md b/examples/protocols/sockets/udp_server/README.md index 31935f28b5..c29ab3ed6b 100644 --- a/examples/protocols/sockets/udp_server/README.md +++ b/examples/protocols/sockets/udp_server/README.md @@ -12,6 +12,7 @@ In order to create UDP client that communicates with UDP server example, choose There are many host-side tools which can be used to interact with the UDP/TCP server/client. One command line tool is [netcat](http://netcat.sourceforge.net) which can send and receive many kinds of packets. Note: please replace `192.168.0.167 3333` with desired IPV4/IPV6 address (displayed in monitor console) and port number in the following commands. +If want to use this RECVINFO function, please enable LWIP_NETBUF_RECVINFO in menuconfig,this function can only resolve the destination address of IPV4. In addition to those tools, simple Python scripts can be found under sockets/scripts directory. Every script is designed to interact with one of the examples. diff --git a/examples/protocols/sockets/udp_server/main/udp_server.c b/examples/protocols/sockets/udp_server/main/udp_server.c index 26ec46bc5f..3db2a89a97 100644 --- a/examples/protocols/sockets/udp_server/main/udp_server.c +++ b/examples/protocols/sockets/udp_server/main/udp_server.c @@ -57,6 +57,11 @@ static void udp_server_task(void *pvParameters) } ESP_LOGI(TAG, "Socket created"); +#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6) + int enable = 1; + lwip_setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable)); +#endif + #if defined(CONFIG_EXAMPLE_IPV4) && defined(CONFIG_EXAMPLE_IPV6) if (addr_family == AF_INET6) { // Note that by default IPV6 binds to both protocols, it is must be disabled @@ -73,13 +78,33 @@ static void udp_server_task(void *pvParameters) } ESP_LOGI(TAG, "Socket bound, port %d", PORT); + struct sockaddr_storage source_addr; // Large enough for both IPv4 or IPv6 + socklen_t socklen = sizeof(source_addr); + +#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6) + struct iovec iov; + struct msghdr msg; + struct cmsghdr *cmsgtmp; + u8_t cmsg_buf[CMSG_SPACE(sizeof(struct in_pktinfo))]; + + iov.iov_base = rx_buffer; + iov.iov_len = sizeof(rx_buffer); + msg.msg_control = cmsg_buf; + msg.msg_controllen = sizeof(cmsg_buf); + msg.msg_flags = 0; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_name = (struct sockaddr *)&source_addr; + msg.msg_namelen = socklen; +#endif + while (1) { - ESP_LOGI(TAG, "Waiting for data"); - struct sockaddr_storage source_addr; // Large enough for both IPv4 or IPv6 - socklen_t socklen = sizeof(source_addr); +#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6) + int len = recvmsg(sock, &msg, 0); +#else int len = recvfrom(sock, rx_buffer, sizeof(rx_buffer) - 1, 0, (struct sockaddr *)&source_addr, &socklen); - +#endif // Error occurred during receiving if (len < 0) { ESP_LOGE(TAG, "recvfrom failed: errno %d", errno); @@ -90,6 +115,15 @@ static void udp_server_task(void *pvParameters) // Get the sender's ip address as string if (source_addr.ss_family == PF_INET) { inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr, addr_str, sizeof(addr_str) - 1); +#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6) + for ( cmsgtmp = CMSG_FIRSTHDR(&msg); cmsgtmp != NULL; cmsgtmp = CMSG_NXTHDR(&msg, cmsgtmp) ) { + if ( cmsgtmp->cmsg_level == IPPROTO_IP && cmsgtmp->cmsg_type == IP_PKTINFO ) { + struct in_pktinfo *pktinfo; + pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsgtmp); + ESP_LOGI(TAG, "dest ip: %s\n", inet_ntoa(pktinfo->ipi_addr)); + } + } +#endif } else if (source_addr.ss_family == PF_INET6) { inet6_ntoa_r(((struct sockaddr_in6 *)&source_addr)->sin6_addr, addr_str, sizeof(addr_str) - 1); } diff --git a/examples/wifi/getting_started/station/main/Kconfig.projbuild b/examples/wifi/getting_started/station/main/Kconfig.projbuild index 7403f8f834..2d127ee20e 100644 --- a/examples/wifi/getting_started/station/main/Kconfig.projbuild +++ b/examples/wifi/getting_started/station/main/Kconfig.projbuild @@ -17,4 +17,29 @@ menu "Example Configuration" default 5 help Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. + + choice ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD + prompt "WiFi Scan auth mode threshold" + default ESP_WIFI_AUTH_OPEN + help + The weakest authmode to accept in the scan mode. + + config ESP_WIFI_AUTH_OPEN + bool "OPEN" + config ESP_WIFI_AUTH_WEP + bool "WEP" + config ESP_WIFI_AUTH_WPA_PSK + bool "WPA PSK" + config ESP_WIFI_AUTH_WPA2_PSK + bool "WPA2 PSK" + config ESP_WIFI_AUTH_WPA_WPA2_PSK + bool "WPA/WPA2 PSK" + config ESP_WIFI_AUTH_WPA3_PSK + bool "WPA3 PSK" + config ESP_WIFI_AUTH_WPA2_WPA3_PSK + bool "WPA2/WPA3 PSK" + config ESP_WIFI_AUTH_WAPI_PSK + bool "WAPI PSK" + endchoice + endmenu diff --git a/examples/wifi/getting_started/station/main/station_example_main.c b/examples/wifi/getting_started/station/main/station_example_main.c index e478a4fc2b..663533cf6a 100644 --- a/examples/wifi/getting_started/station/main/station_example_main.c +++ b/examples/wifi/getting_started/station/main/station_example_main.c @@ -28,6 +28,24 @@ #define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY +#if CONFIG_ESP_WIFI_AUTH_OPEN +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN +#elif CONFIG_ESP_WIFI_AUTH_WEP +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP +#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK +#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK +#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK +#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK +#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK +#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK +#endif + /* FreeRTOS event group to signal when we are connected*/ static EventGroupHandle_t s_wifi_event_group; @@ -41,6 +59,7 @@ static const char *TAG = "wifi station"; static int s_retry_num = 0; + static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { @@ -95,7 +114,7 @@ void wifi_init_sta(void) /* Setting a password implies station will connect to all security modes including WEP/WPA. * However these modes are deprecated and not advisable to be used. Incase your Access point * doesn't support WPA2, these mode can be enabled by commenting below line */ - .threshold.authmode = WIFI_AUTH_WPA2_PSK, + .threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD, }, }; ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); @@ -123,11 +142,6 @@ void wifi_init_sta(void) } else { ESP_LOGE(TAG, "UNEXPECTED EVENT"); } - - /* The event will not be processed after unregister */ - ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip)); - ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id)); - vEventGroupDelete(s_wifi_event_group); } void app_main(void)