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 061b5bbe07..dfae6c9270 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_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index 2c7677ab86..e3dc51463e 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -1855,7 +1855,7 @@ pm_on_data_rx = 0x400054c0; pm_on_tbtt = 0x400054cc; pm_parse_beacon = 0x400054d8; pm_process_tim = 0x400054e4; -pm_rx_beacon_process = 0x400054f0; +/*pm_rx_beacon_process = 0x400054f0;*/ pm_rx_data_process = 0x400054fc; /*pm_sleep = 0x40005508;*/ pm_sleep_for = 0x40005514; @@ -2032,7 +2032,7 @@ ieee80211_is_tx_allowed = 0x40005a78; ieee80211_output_pending_eb = 0x40005a84; ieee80211_output_process = 0x40005a90; ieee80211_set_tx_desc = 0x40005a9c; -sta_input = 0x40005aa8; +/*sta_input = 0x40005aa8;*/ wifi_get_macaddr = 0x40005ab4; wifi_rf_phy_disable = 0x40005ac0; wifi_rf_phy_enable = 0x40005acc; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index b28a4656cf..dc92d42a73 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit b28a4656cfeee7d444d06c0c459d1de59562706d +Subproject commit dc92d42a7393277597759a91e99e80fdd3f81da5 diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 45c068b8b1..57e8c2b045 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -1018,6 +1018,13 @@ menu "LWIP" All lwIP debug features increase the size of the final binary. + 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 f17c49783a..8f0ffa60e3 100644 --- a/components/lwip/port/esp32/include/arch/cc.h +++ b/components/lwip/port/esp32/include/arch/cc.h @@ -79,7 +79,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/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); }